智能表-angularJs-ajax刷新表
我正在使用angularjs mudule智能表 我的表具有服务器端处理,所有数据加载都位于服务器上。我想在桌子外面有一个刷新按钮智能表-angularJs-ajax刷新表,angularjs,ajax,smart-table,Angularjs,Ajax,Smart Table,我正在使用angularjs mudule智能表 我的表具有服务器端处理,所有数据加载都位于服务器上。我想在桌子外面有一个刷新按钮 this.tableState = null; this.callServer = function callServer(tableState) { ctrl.tableState = tableState; ... } this.refreshGrid = function(){
this.tableState = null;
this.callServer = function callServer(tableState) {
ctrl.tableState = tableState;
...
}
this.refreshGrid = function(){
ctrl.callServer(ctrl.tableState);
}
这是一个调用服务器的函数,我希望能够手动调用它,但我不知道如何在my controller中检索表状态
this.callServer = function callServer(tableState) {
ctrl.isLoading = true;
var pagination = tableState.pagination;
var start = pagination.start || 0; // This is NOT the page number, but the index of item in the list that you want to use to display the table.
var number = pagination.number || 10; // Number of entries showed per page.
service.getPage(start, number, tableState, ctrl.startDateFilter,
ctrl.endDateFilter).then(function (result) {
ctrl.displayed = result.data;
tableState.pagination.numberOfPages = result.numberOfPages;
ctrl.isLoading = false;
});
};
我的目标是有一个这样的函数,如何获得表状态
this.refreshTable = function(){
tableState = getTableState();
ctrl.callServer(tableState);
}
解决方案是将表状态放入控制器变量中 每次调用callServer函数时,它都会更新此变量。这样,我就可以刷新表了
this.tableState = null;
this.callServer = function callServer(tableState) {
ctrl.tableState = tableState;
...
}
this.refreshGrid = function(){
ctrl.callServer(ctrl.tableState);
}
您还可以创建一个指令来执行此操作 查看
<table st-pipe="productsTableCtrl.getTableData"
st-table="productsTableCtrl.tableData" refresh-table>
指令
app.directive("refreshTable", function(){
return {
require:'stTable',
restrict: "A",
link:function(scope,elem,attr,table){
scope.$on("refreshMyTable", function() {
table.pipe(table.tableState());
});
}
}});
gtaylor44的学分: