How to have select filter in ngtable?

こ雲淡風輕ζ 提交于 2019-11-28 14:40:13
  1. Need exact filter match

ng-table doesn't actually apply the filters the data - it's only responsible for collecting the filter values from the user.

In your getData function you've configured ng-table with, you are using the angular $filter service to apply the filter. It's this service that is responsible for doing the actual filtering. Therefore if you want an exact match behaviour you will need to use something other than $filter.

  1. ...extra blank entry which is removed once user selects and clicks the select filter again

UPDATE: I have edited my previous answer.

I've fixed this particular issue with ng-table. Here's a conversation about the problem: https://github.com/esvit/ng-table/pull/654#issuecomment-127095189

The commit for the fix: 1ee441

  1. Auto width of ngtable w.r.t it's data.

Column widths for the rendered html table are controlled using css. ng-table does not add anything specific. You should create your own style rules to change the widths. Tip: you can also use colgroup in the html markup and assign a specific width to each <col> tag

if Okonomy is saying that you could just do the following

filter="{ 'name': 'select' : true }"

<td data-title="'Status'" class="text-center" header-class="text-center" width="40px" filter="{ 'name': 'select' : true }" sortable="'status'" filter-data="filterAgentStatus($column)"><img ng-src="{{ item.status }}" /></td>

i did not find this to be true. You would need to go into the .js file controlling that page and do something more like the below.

var newStudies = $filter('filter')(controller.TableData, params.filter(), true);

But this forces all filters in the table to exact match (and therefore your table would be empty). So you have to make a custom filter. There are examples of custom attributes here in the below link. Not great examples, but it is an example: custom filter example for ng-table

  • In order for filterAgentStatus to run, you have to change 'select' to 'select-multiple'. (You probably can override the default template of 'select-multiple' in order to have single select at 'select-multiple'):

<td data-title="'Status'" class="text-center" header-class="text-center" width="40px" filter="{ 'name': 'select-multiple' }" sortable="'status'" filter-data="filterAgentStatus($column)"><img ng-src="{{ item.status }}" /></td>

Note: I think you better pass item to filterAgentStatus, instead of $column: filterAgentStatus(item).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!