Alterative to queryParam and respondHandler

Alterative to queryParam and respondHandler

yvan.dupre79yvan.dupre79 Posts: 1Questions: 0Answers: 0

Actually i try to migrate bootstrap datatable from
bootstrap-table.wenzhixin.net.cn/

Is there a way to mach parameter of datable sent to the server and do a mathing with the value received from the server?

With bootstrap table respondHandler and queryParams was used for that.

$("#carsTableResult").bootstrapTable({
                    url: getHostName() + "/cars/";
                    silent: true,
                    queryParamsType: "",
                    responseHandler: function (res) {
                        return {
                            rows: res.content,
                            total: res.totalElements,
                            pageNumber: res.number,
                            pageSize: res.size
                        };
                    },
                    queryParams: function (params) { //todo check if we need to put search here
                        return {   
                            search: params.searchText,
                            page: params.pageNumber - 1,
                            size: params.pageSize,
                            sort: params.sortName + "," + params.sortOrder
                        };
                    }

                });

Replies

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Yes but in the long run it would be more efficient to change your sever side code to handle and provide what datatables expect.

    Having said that, you can used the data attribute in the ajax call in data tables to convert what datatables provides to what your sever expects.

    On the return, there are a couple of places where you can intercept the response, such as the dataFilter section, to convert what your server sends out to what datatables expects.

  • marcpiratmarcpirat Posts: 51Questions: 18Answers: 0

    i try to do the same thing... what you mean by dataFilter don't see any function with this name

  • marcpiratmarcpirat Posts: 51Questions: 18Answers: 0

    maybe like this

    $('#myTable').DataTable( {
        serverSide: true,
        ajax: {
            url: '/api/data',
            dataFilter: function(data){
                var json = jQuery.parseJSON( data );
                json.recordsTotal = json.total;
                json.recordsFiltered = json.total;
                json.data = json.list;
     
                return JSON.stringify( json ); // return JSON string
            }
        }
    } );
    
This discussion has been closed.