1

Hi Im trying to implement the server side search using the select input with datatable but it doesn't seem to pass the selected input value to the server side.

basically it populates the input list in the footer and fires this on change event but doesn't pass the selected value to the server side...

am i missing something ? some help would be very appreciated.

var table = $('#tbl_product_list');

        // begin first table
        table.dataTable({

            // Internationalisation. For more info refer to http://datatables.net/manual/i18n

             "processing": true,
             "serverSide": true,
             "ajax":
             {
                 "url": "/Product/GetProductData",
                 "type": "POST",
                 "dataType": "JSON"
             },




             "columns": [                 
                 {
                     "data": "ProductName"
                 },
                 {
                     "data": "ProductCategory"
                 },
                 {
                     "data": "ProductType"
                 },
                 {
                     "data": "ProductSize"
                 },
                 {
                     "data": "CurrentQuantity"
                 },
                 { "data": null, "defaultContent": "<button class='btn btn-s yellow-gold ajax-edit' data-toggle='modal' type='button'> 수정 </button>" }
             ],               


            "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.

            "lengthMenu": [
                [10, 20, 30, 40,50],
                [10, 20, 30, 40,50] // change per page values here
            ],

            // set the initial value
            "pageLength": 10,            
            "pagingType": "bootstrap_full_number",

            "order": [
                [0, "asc"]
            ],
            "createdRow": function (row, data, dataIndex) {
                $(row).find('td:eq(12) button').attr('data-url',  '/Product/GetProductEditForm/' + data["ProductID"]);                 
            },
            "initComplete": function () {

                this.api().columns([1, 2, 3]).every(function () {
                    var column = this;
                    var select = $('<select class="form-control input-sm"><option value=""></option></select>')
                        .appendTo($(column.footer()).empty())
                        .on('change', function () {
                            var val = $.fn.dataTable.util.escapeRegex(
                                $(this).val()
                            );
                            console.log(val);       
                            this.search(val).draw();
                        });

                    column.data().unique().sort().each(function (d, j) {
                        select.append('<option value="' + d + '">' + d + '</option>')
                    });
                });
            }
        });        
    }
superted
  • 315
  • 1
  • 8
  • 21

1 Answers1

1

Individual column search values are sent with a parameter columns[i][search][value] which differs from parameter that holds global search value search[value].

See Server-side processing for more details.

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
  • I know it's not a good way to redirect any member but trust me I am trying this issue from last 3 days but still not found the solution. Can you help me in this link https://stackoverflow.com/questions/63360592/search-and-pagination-not-working-while-using-server-side – user9437856 Aug 14 '20 at 18:29
  • @user9437856, just responded to your other question. – Gyrocode.com Aug 14 '20 at 18:52