ng-click
and calling a function when the table header field is clicked. Using the class of the header field, I can see whether the sort order is ascent
or descent
. But doing so involves a lot of hacks. If there is a cleaner way built into the smart table library, that would be great
yea looks like it. overriding the stPipe
function should do the trick. It contains information in the following format
"sort": {
"predicate": "id",
"reverse": false
},
"search": {},
"pagination": {
"start": 0,
"totalItemCount": 0
}
}
Examining this tableState
object, I can send the required calls to server and update the data in rowCollection
. This is awesome!
stPipe
function using some button ? The function gets triggered on search, sort action. I want to be able to trigger the same function using some buttons. These buttons serve as filter functions. I can write the function and bind it to ng-click of that button but not sure how to trigger the table's stPipe
function and how to access the tableState
<table class="table table-hover" st-table="shoplists" st-safe-src="shoplists_data" >
$http
service, or something else, something non-Angular?
.factory('Shop',['$resource',function($resource){
var obj={};
obj=$resource('http://127.0.0.1:8080/api/shops');
obj.baseinfo=$resource('http://127.0.0.1:8080/api/shops/baseinfo');
obj.getNotVerifyShops=$resource('http://127.0.0.1:8080/api/shops/getNotVerifyShops',{},{isArray:true});
obj.getShopByQuery=$resource('http://127.0.0.1:8080/api/shops/getShopByQuery',{},{ isArray:true});
return obj;
}])
<div>Data count: {{shoplist_data.length}}</div>
$scope.shoplists = [];
$scope.shoplists_data = [];
function getNotVerifyShops() {
Shop.getNotVerifyShops.query(function(data){
console.log(data);
$scope.shoplists_data = data;
// $scope.shoplists = data;
})
}
getNotVerifyShops()
<div>Data count: {{shoplist_data.length}}</div>
<table class="table table-hover" st-table="shoplists" st-safe-src="shoplists_data" >
<thead>
<tr class="sortable">
<th class="table-id" st-sort="shopId" st-sort-default="true">编号</th>
<!-- <th st-sort="area">区域</th> -->
<th st-sort="company">申请公司</th>
<th st-sort="person">联系人</th>
<th st-sort="phone">手机号码</th>
<th st-sort="state">当前状态</th>
<th st-sort="date">最近提交时间</th>
<th st-sort="zaozuo">操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in shoplists_data" class="editable-tr-wrap">
<td class="table-id">{{item.shopId}}</td>
<!-- <td>{{item.area}}</td> -->
<td>{{item.companyName}}</td>
<td>{{item.shopApplyUserId.name}}</td>
<td>{{item.shopApplyUserId.cellphone}}</td>
<td>{{test(item.applyId.verify)}}</td>
<td>{{spliceTime(item.meta.createAt)}}</td>
<!-- <td>{{item.date}}</td> -->
<td><a ui-sref="components.check({obj:item._id})">审核</a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="8" class="text-center">
<div st-pagination="" st-items-by-page="5" st-displayed-pages="5"></div>
</td>
</tr>
</tfoot>
</table>
st-safe-src
is very badly documented on the Smart-Table site. They do however show that st-table
should point to "displayed" data, but I don't think there is any mention of what that means and what "displayed" data should be