admin管理员组

文章数量:1356753

I'm using the Javascript Datatable with server side searching.

So:

var table = $('#myTable').DataTable({
                responsive: true,
                serverSide: true,
                ajax: {
                    url: myUrl,
                    dataSrc: ''
                },
                fnServerData: function (sSource, aoData, fnCallback, oSettings) 
                {
                    oSettings.jqXHR = $.ajax({
                        url: myUrl,
                        success: function (json, status, xhr) {
                            //Do stuff
                        }
                    });
                }    
            });

I build the url dynamically using options set on my form.

I would like a button on my form so I can manually trigger the fnServerData function. At the moment I have to type into the included search box.

e.g. <button ng-click="model.search()">Search</button>

Is this possible?

Thanks

I'm using the Javascript Datatable with server side searching.

So:

var table = $('#myTable').DataTable({
                responsive: true,
                serverSide: true,
                ajax: {
                    url: myUrl,
                    dataSrc: ''
                },
                fnServerData: function (sSource, aoData, fnCallback, oSettings) 
                {
                    oSettings.jqXHR = $.ajax({
                        url: myUrl,
                        success: function (json, status, xhr) {
                            //Do stuff
                        }
                    });
                }    
            });

I build the url dynamically using options set on my form.

I would like a button on my form so I can manually trigger the fnServerData function. At the moment I have to type into the included search box.

e.g. <button ng-click="model.search()">Search</button>

Is this possible?

Thanks

Share Improve this question edited Jan 24, 2018 at 16:11 Sun asked Jan 24, 2018 at 15:52 SunSun 4,71816 gold badges73 silver badges116 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Here is the code that I used for refresh the DataTable

 var table = $("#gridId").dataTable();
//if you want to add extra parameters in the query
/*table.fnSettings().ajax.data = function (d) {
            $.extend(d, jsonPostData);
        };
*/
table.fnDraw(false);

I've found a solution:

var oTable = $('#myTable').dataTable();
oTable.fnFilter('');

With the latest DataTable, you need to use following in order to trigger server side call:

table.draw();

本文标签: javascriptManually trigger jquery Datatable searchStack Overflow