如何通过下拉值更改来更改jquery数据表的值

How to change jquery datatable value by dropdown value change

本文关键字:jquery 数据表 何通过      更新时间:2023-09-26

我使用jquery datatable根据下拉列表值显示表数据,我使用ajax从表中获取数据。

问题是,当表第一次加载时,它运行良好,但当我点击排序或搜索时,它显示的处理过程在我刷新页面之前不会改变,代码如下:

        $( document ).ready(function() {

                var table = $('#example').DataTable({
                    //"bProcessing": true,
                    //"sAjaxSource": "response.php",
                    "processing": true,
                    "serverSide": true,
                    //"bDestroy": true,
//                "bJQueryUI": true,
                    "aoColumns": [
                        { mData: 'FNAME' } ,
                        { mData: 'FPRICE' },
                        { mData: 'IMGPATH' },
                        { mData: 'FDESC' },
                        { mData: 'CID' }
                    ],

                    "ajax": {
                        'type': 'POST',
                        'url': 'response.php',
                        'data': {id: $('#myselect').val()}
//                    "success":function (res) {
//
//                    }
                    }
                });
            $('#myselect').change(function() {
                var item = $(this).val();
                // alert(item)
                var urld = 'response.php/'+item;
                table.ajax.url(urld).load();
                table.reload();
            });
//            setInterval( function () {
//                table.ajax.reload();
//            }, 10000 );
                //table.fnDraw();


        });

如果您正在使用服务器端处理,请检查此项以进行自定义排序https://datatables.net/forums/discussion/9857/server-side-processing-custom-sort-solution-like-formatted-num-sorting-plug-in