Manjit Singh Manjit Singh - 4 months ago 91
AngularJS Question

Reload the bootstrap datatable after every minute?

I am using bootstrap server side datatable in my angularjs application and now i want to reload the data of that datatable after every minute.
So how can i do it?
I am using the following code:

HTML:

<table bs-table-control="matterTableControl" id="matterTableControl"></table>


Controller:

$scope.getMatterTable = (function () {
$scope.matterTableControl = {
options : {
toolbar : "#get",
url : url,
dataField : 'rows',
cache : false,
sidePagination : 'server',
pagination : false,
showExport : false,
queryParams : queryParams,
clickToSelect : true,
onClickRow : onClickRow,
maintainSelected : true,
columns : [{
field : 'ClientName',
title : 'Client',
align : 'left',
valign : 'bottom',
sortable : false
}, {
field : 'Name',
title : 'Matter',
align : 'left',
valign : 'bottom',
sortable : false
}
]
}
}
});


I am trying to reload this by using following code but getting no success:

$interval(function () {
$scope.getMatterTable();
}.bind(this), 60000);


Documentation of Datatable:
http://bootstrap-table.wenzhixin.net.cn/documentation/

Example:
http://issues.wenzhixin.net.cn/bootstrap-table/#integrate/angular

Github Code of datatable:
https://github.com/wenzhixin/bootstrap-table-examples/tree/master/integrate/angular

Answer

Bootstrap datatables ve a proper method to refresh the table:

angular.element( document.querySelector( '#matterTableControl' ) ).bootstrapTable('refresh');

it basically do this:

BootstrapTable.prototype.refresh = function (params) {
    if (params && params.url) {
        this.options.url = params.url;
        this.options.pageNumber = 1;
    }
    this.initServer(params && params.silent, params && params.query);
};

Example