Faith
Faith

Reputation: 19

DataTable 1.10x jQuery Column Filter through a input textbox Server Side

I am having trouble with the DataTable 1.10 Column Filtering through a input element.

jQuery(document).ready(function() {    

    dt_table = $('#datatable_list').DataTable( {
        "dom": "<'top'i>rt<'table-scrollable't>lp",
        "processing": true,
        "serverSide": true,
        "ajax": "ajax/list_json.php",
        "pageLength": 10,
        "autoWidth": false
    }); 

    $('#quickfind').on( 'keyup', function () { dt_table.search( this.value ).draw(); } );

});

As you can see I am using the Server Side processing with a json output. The total list is filling good.

In the table there is a footer with 4 inputs:

    <tfoot>
        <tr>
            <th><input type="text" id="filters_0" name="filters_0" class="form-control form-filter"></th>
            <th><input type="text" id="filters_1" name="filters_1" class="form-control form-filter"></th>
            <th><input type="text" id="filters_2" name="filters_2" class="form-control form-filter"></th>
            <th><input type="text" id="filters_3" name="filters_3" class="form-control form-filter"></th>
        </tr>
    </tfoot>

I am using the standard ssp.class.php class. Please i am working like for 4 days with this simple column filtering project.

What i want is simple. The quickfind textbox is working great for searching the whole table. But i want to filter also for each column. Like 'filters_0' is the ID of the product. But this will not work.

Please understand that I am using the latest DataTabes 1.10.

Upvotes: 0

Views: 1022

Answers (1)

Glaubule
Glaubule

Reputation: 169

You first have to serialize your fields (in the tfoot) before passing them as a search data. I use an external form and when it is submitted, simply do this :

dt_table = $('#datatable_list');
var formData = $('#search-form-orders').serialize();
dt_table.search( formData ).draw();

Then on server side, I do not use SSP but an custom framework, so :

// get the 'search' array from $_GET and don't forget to clean it !!!
if( $search['value'] !=='' )
    foreach (explode('&', $search['value']) as $chunk) {
        $param = explode("=", $chunk);
        $field = urldecode($param[0]);
        $value = urldecode($param[1]);
        $criterias[] = array( $field => $value );
    }

And finally treat the criterias to build the request

Upvotes: 1

Related Questions