How can I put a placeholder text on ng-table select filter?

女生的网名这么多〃 提交于 2019-12-13 06:59:54

问题


Code sample: https://plnkr.co/edit/hdYjHtEx1Dto1q6UVCS9

$scope.idFilter = {
    id: {
      id: "number",
      placeholder: "Filter by id", // Working
    }
  };

  $scope.nameFilter = {
    id: {
      id: "text",
      placeholder: "Filter by name", // Working
    }
  };

  $scope.statusFilter = {
    status: {
      id: "select",
      placeholder: "Filter by status", // Not working
    }
  };

It is easy to add a placeholder on a number or text filters in ngTable. However I could not manage to find a solution for select filter. I know that placeholder on a 'select' element is not trivial by itself, but it is achievable.

Can you find a solution for it in ngTable?
If not, can you recommend another table component that have this feature?


回答1:


You can add extra option in your select with val:'' to simulate placeholder:

{
  id: '',
  title: 'Filter by Status'
}

And add default filter to refer "Filter by Status"

$scope.myTableParams = new NgTableParams({filter: { status: ""}}, {
    counts: [],
    dataset: users
});

Result: https://plnkr.co/edit/luaas1dExIuCYMa4WtN3?p=preview


Update:
Add this CSS in order to distinct the placeholder look from other selections:

/* Set the select filter placeholder item look */
table.ng-table select.filter-select.ng-empty {
  color: gray;
}

/* Prevent select filter placeholder look to cascade to its options */
table.ng-table select.filter-select > option {
  color: #767676;
}


来源:https://stackoverflow.com/questions/38725612/how-can-i-put-a-placeholder-text-on-ng-table-select-filter

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