有没有办法在智能表中使用条件st排序?示例-我有一个数组,它告诉我表中哪些列是可排序的。假设我的表有FirstName,LastName,Age,email列,我的排序数组是firstName,age,这意味着只有名字和年龄字段是排序的。我如何使用智能桌面来实现这一点。任何帮助都是非常感谢的!谢谢!!
发布于 2015-10-30 21:25:15
智能表希望您指定列是否可排序的方法是在<thead>中使用st-sort指令,它告诉您哪一列应该按什么对象属性排序,如下所示:
<thead>
<tr>
<th st-sort="firstName">first name</th> <!-- sortable rows -->
<th st-sort="lastName">last name</th>
<th st-sort="age">age</th>
<th>email</th> <!-- not sortable -->
</tr>
</thead>您的意思是,您有一个数组,它告诉您的表哪一列是可排序的,哪一列是不可排序的。在我看来,一般来说,这是一种非常笨拙的方式,在ST中也不能很好地做到这一点。
但是,您可以编写一个指令,使用数组中的值有条件地在表中添加或删除st-sort。但那只会是一团糟
发布于 2015-11-02 14:27:09
我承认这是一种笨拙的方式,但这就是服务向我们返回数据的方式。我尝试了以下代码并使其正常工作(它对firstname和age列进行排序。),尽管它对我来说似乎不是一种非常干净的方法-
在我的HTML中-
<thead>
<tr>
<th st-ratio="20" ng-attr-st-sort="sorters.getSorter('firstName')">first name</th> <!-- sortable rows -->
<th st-ratio="20" ng-attr-st-sort="sorters.getSorter('lastName')">last name</th>
<th st-ratio="10" ng-attr-st-sort="sorters.getSorter('age')">age</th>
<th st-ratio="30" ng-attr-st-sort="sorters.getSorter('email')">email</th>
<th st-ratio="20" ng-attr-st-sort="sorters.getSorter('balance')">balance</th>
</tr>
</thead> enter code here
在我的js里-
$scope.sorters = {
getSorter: function(prop){
return function(value){
var sortables = ['firstName', 'age'];
for(var i=0;i<sortables.length; i++){
if(sortables[i] === prop) {
return value[prop];
};
}
return undefined;
}
}
}; 虽然这解决了我的问题,但我不喜欢这种方法。有没有更好的选择呢?附言-如果我没有更好的选择,我最终会将其转换为指令。
https://stackoverflow.com/questions/33433199
复制相似问题