在服务器端DataTable上搜索单个列

时间:2016-02-19 08:23:20

标签: javascript jquery asp.net asp.net-mvc-4

我想应用单个列搜索。在页脚下拉列中只显示第一页选项,在选择任何选项时它不能过滤任何记录。我希望所有记录都显示在下拉列中。在客户端表中代码工作正常。

function CallToServer() {
                oTable = $('#' + tableId).dataTable({

                    //'sPaginationType': 'full_numbers',
                    "sScrollY": "auto",
                    'bPaginate': true,
                    'iDisplayLength': 10,
                    'bProcessing': true,
                    "bStateSave": true,
                    'bFilter': true,
                    'bServerSide': true,
                    "language": {
                        "searchPlaceholder": "Search",
                        "lengthMenu": "Showing _MENU_ Projects",
                        "zeroRecords": "Sorry no Project(s) found",
                        "info": "Showing _START_ of _END_ of _TOTAL_ Projects",
                        "infoEmpty": "No Project(s) found",
                        "infoFiltered": "(filtered from MAX total Projects)"
                    },
                    "aaSorting": [[2]],
                    "aoColumns": [
                       { "bSortable": true, "bvsible": false },
                        { "bSortable": true, "class": "test" },
                        { "bSortable": true, "class": "test" },
                        { "bSortable": true, "class": "test" },
                        { "bSortable": true, "class": "test" },
                        //{ "bSortable": true, "class": "test" }
                       ],
                    responsive: true,
                    'sAjaxSource': ws_GetData,
                    "fnServerData": function (sSource, aoData, fnCallback) { GrabData(sSource, aoData, fnCallback); }
                    , initComplete: function () {

                        this.api().columns().every(function () {

                                var column = this;
                                var select = $('<select><option value="">All Projects</option></select>')
                                    .appendTo($(column.footer()).empty())
                                    .on('change', function () {
                                        var val = $.fn.dataTable.util.escapeRegex(
                                            $(this).val()
                                        );

                                        column
                                            .search(val ? '^' + val + '$' : '', true, false)

                                            .draw();
                                    });
                                column.data().unique().sort().each(function (d, j) {
                                    //var anchor = d;
                                    //anchor = anchor.substring(anchor.indexOf(">") + 1);
                                    //anchor = anchor.substring(0, anchor.indexOf("<"));
                                    //alert(anchor);


                                    select.append('<option value="' + d + '">' + d + '</option>')
                                });


                        });
                    }
                });



                $('#' + tableId + ' tbody tr').live('click', function () {

                    $(oTable.fnSettings().aoData).each(function () { $(this.nTr).removeClass('row_selected'); });

                    $(this).addClass('row_selected');

                    //var aPos = oTable.fnGetPosition(this);
                    //var aData = oTable.fnGetData(this);
                    //iId = aData[0];
                });
            }

0 个答案:

没有答案