Datatables custom filtering with server side

孤街浪徒 提交于 2019-11-30 18:37:39

Here is a very nice explanation on how to do it: https://datatables.net/reference/option/ajax.data

I am currently using this code:

"ajax": {"url":"/someURL/Backend",
        "data": function ( d ) {
                  return $.extend( {}, d, {
                    "parameterName": $('#fieldIDName').val(),
                    "parameterName2": $('#fieldIDName2').val()
                  } );
        }
}

You call it by doing the following:

$('#myselectid').change(function (e) {
        table.draw();
});

If you want to submit by clicking on the button, change the .change to .click and make sure that ID is pointing to button's id in a HTML

You've almost got it. You just need to assign the filter var to the data parameter that's passed in the datatables request:

"ajax": {
     "url": "/getdata",
     "data": {
     "friend_name": $('#myselectid').val();
    }
} 

And to filter the data, just call draw() on the select change event

$('#myselectid').change(function (e) {
        table.fnDraw();
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!