如何使用AngularJS而不是在查询子句中根据两列的差异对表进行排序
How to sort a table by difference of two columns using AngularJS and not in a query clause?
下面是一些代码。我刚刚发布了主html表我需要知道如何对我的表进行排序(字段:vote_value AND vote_dismised_value)。
排序需要如下:按vote_value排序-votedistissed_value。
怎么做?使用AngularJS而不使用sql查询子句。
感谢
table.gridtable {
font-family: verdana, arial, sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
the html table that needs to be sorted
<div>
<table class="gridtable" ng-show="entity.currentFilter.id">
<tbody>
<tr>
<th>#</th>
<th>Name</th>
<th>Vote Value</th>
<th>Vote Dismissed Value</th>
<th>Vote Total</th>
<th>is Winner</th>
</tr>
<!-- NNN Angular repeat -->
<tr ng-repeat="element in entity.currentPage.items | orderBy:['-vote_value']">
<td>{{ tag.ng("$index + 1") }}</td>
<td>{{ tag.ng("element.name") }}</td>
<td class="text-danger">{{ tag.ng("element.vote_value") }}</td>
<td class="text-warning">{{ tag.ng("element.vote_dismissed_value") }}</td>
<td class="text-success">{{ tag.ng("element.vote_value - element.vote_dismissed_value") }}</td>
<td>
<div class="iphone-toggle-buttons">
<label>
<input type="checkbox" ng-model="element.state_win" ng-true-value="1" ng-false-value="0" ng-change="updateCurrentCompetitorState(element)">
<span>
</span>
</label>
</div>
</td>
</tr>
</tbody>
</table>
</div>
好吧,我想好了。。。
对我来说,有效的答案是改变排序。像这样:
<table class="table" ng-show="entity.currentFilter.id">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Vote Value</th>
<th>Vote Dismissed Value</th>
<th>Vote Total</th>
<th>is Winner</th>
</tr>
</thead>
<tbody>
<!-- NNN Angular repeat -->
<tr ng-repeat="element in entity.currentPage.items | orderBy:myCustomSortFunction:true">
<td>{{ tag.ng("$index + 1") }}</td>
<td>{{ tag.ng("element.name") }}</td>
<td class="text-danger">{{ tag.ng("element.vote_value") }}</td>
<td class="text-warning">{{ tag.ng("element.vote_dismissed_value") }}</td>
<td class="text-success">{{ tag.ng("element.vote_value - element.vote_dismissed_value") }}</td>
<td>
<div class="iphone-toggle-buttons">
<label>
<input type="checkbox" ng-model="element.state_win" ng-true-value="1" ng-false-value="0" ng-change="updateCurrentCompetitorState(element)">
<span>
</span>
</label>
</div>
</td>
</tr>
</tbody>
</table>
before:orderBy:['-vote_value']AND after:orderBy:myCustomSortFunction:true
javascript函数为:
$scope.myCustomSortFunction = function(Element) {
return Element.vote_value - Element.vote_dismissed_value;
}
工作jsFiddle答案在这里找到
相关文章:
- 带组的两列html表
- 单个交叉筛选器维度和两列上的组
- 使用 php 将类别和子类别显示为两列
- 将网格视图的两列相乘,并将其显示在新列中
- 我的表排序器中的列排序将覆盖表标题中的复选框
- Angular ng sortable-如果我在一个栏中添加了一个搜索框,则拖放在两列之间无法正常工作
- 将列表拆分为两列.列表没有't具有块,但是需要在最接近的<p>标签
- 在两列中动态显示产品
- 两列全高布局展开以包含内容
- 计算文本块中的字符数,并将其拆分为两列
- 如何使用AngularJS而不是在查询子句中根据两列的差异对表进行排序
- jqgrid:基于两列排序
- jQuery可排序列表分为两列
- 基于两列之间的计算对jquery数据表进行排序
- 两列jQuery.有顺序的可排序列表
- Tiny Table,如何基于两列进行初始排序
- 排序集合与两列首先由一列,然后由第二列在Backbone.js
- 表在两列上排序
- 使用数据表按两列排序(不能读取property ' style '未定义)
- 如何按两列对 jquery-datatable 进行排序