institut-de-genomique / Ultimate-DataTable

This AngularJS directive generate a HTML table with build-in fonctionnality like save, edit, remove, pagination etc...
http://institut-de-genomique.github.io/Ultimate-DataTable/
45 stars 26 forks source link

Remote Demo or exampels #31

Closed AviShmueli closed 8 years ago

AviShmueli commented 8 years ago

Hi, Is there an example for use in server-side functionality such as search, filtering, sorting and pagination? In the demo and the Doc, there are examples just for "local" functionality, and I need them to work in "remote" mode. Thanks...

galbini commented 8 years ago

Hi,

See below ho to use the remote mode but i advise to use only search in remote mode because if you use sorting and pagination in remote mode the CSV export and group features work only on the current page and not all the results. In my enterprise application i only use search in remote and the performance of sorting and pagination are good.

  1. Search

A. Configuration

var datatableConfig = {
                search:{
                        active:true,
                        url:'/api/books'
                }
};

$scope.datatable = datatable(datatableConfig);

B. Server side call


//your object map in the html form
var bookForm : {
           authorName:'king'
 };

//search function call by submit button
$scope.search = function(){
            $scope.datatable.search($scope.bookForm);
};

C. Server side execution
Your server side function need to return a specific JSON object to UDT.
 {
           data:[], //all the data do tou want display in UDT
           recordsNumber:undefined //the number of all result not only the current page
 };

2. Pagination
A. Configuration
```javascript
var datatableConfig = {
                search:{
                        active:true,
                        url:'/api/books'
                },
                pagination:{
                        active:true,
                        mode:'remote' //default mode
                },
};

$scope.datatable = datatable(datatableConfig);

B. Server Side Your server function that execute the search need to manage two parameters add by UDT when search :

var datatableConfig = {
                search:{
                        active:true,
                        url:'/api/books'
                },
                pagination:{
                        active:true,
                        mode:'remote' //default mode
                },
                 order:{
                        active:true,
                        mode:'remote' //default mode
                },            
};

$scope.datatable = datatable(datatableConfig);

B. Server Side Your server function that execute the search need to manage two parameters add by UDT when search :

I hope that help you to use UDT.

Regards, Guillaume

AviShmueli commented 8 years ago

Very helpful. Thank you!

sahapsoft commented 6 years ago

How do I pass the following value from client side to server side?

sahapsoft commented 6 years ago

pageNumber : number of the page numberRecordsPerPage : how many result on one page

sahapsoft commented 6 years ago

Just added: "search":{ "active":true, "url":'admin/alluser' }, "pagination" : {

"active":true,
"mode" : 'remote'

} Got the desired API call URL: http://localhost:9026/portal/admin/alluser?datatable=true&numberRecordsPerPage=10&pageNumber=2&paginationMode=remote

galbini commented 6 years ago

Hello,

Your configuration seem good, now you need to call the function search() in UDT. The function search can be link with a submit form button and you can pass the form (json object) to the search function.

sahapsoft commented 6 years ago

I'm getting following error with AngularJs 1.6.4 version TypeError: $http.get(...).success is not a function at Object._search (ultimate-datatable-3.3.1-SNAPSHOT.js:327) at Object.searchWithLastParams (ultimate-datatable-3.3.1-SNAPSHOT.js:344) at Object.setNumberRecordsPerPage (ultimate-datatable-3.3.1-SNAPSHOT.js:971) at ultimate-datatable-3.3.1-SNAPSHOT.js:3644 at angular.min.js:161 at e (angular.min.js:48) at angular.min.js:51 "Possibly unhandled rejection: {}"

$http.get(url(), { params: this.getParams(params), datatable: this }).success(function(data, status, headers, config) { config.datatable._setData(data.data, data.recordsNumber); that.computeDisplayResultTimeOut.then(function() { that.setSpinner(false); }); });

It seems that AngularJS1.6.4 is not supporting ".success".

sahapsoft commented 6 years ago

I have changed this .success to .then : if (url) { this.setSpinner(true); var that = this; $http.get(url(), { params: this.getParams(params), datatable: this })/.success(function(data, status, headers, config) { config.datatable._setData(data.data, data.recordsNumber); that.computeDisplayResultTimeOut.then(function() { that.setSpinner(false); }); });/ .then(function (response) {

                                    var data = response.data;
                                    var status = response.status;
                                    var statusText = response.statusText;
                                    var headers = response.headers;
                                    var config = response.config;        
                                    config.datatable._setData(data, data.recordsNumber);
                                    that.computeDisplayResultTimeOut.then(function() {
                                    that.setSpinner(false);        
                                    })
                                    console.log(data);
                                });

Now working

galbini commented 6 years ago

Cool, I need to upgrade to angular 1.6. Best regards, Guillaume

sahapsoft commented 6 years ago

Any estimated timeline? Depending on that I will keep 1.6.4 or downgrade to 1.5.8

galbini commented 6 years ago

No estimated timeline for the angularjs upgrade, i hope during the next 6 month.