Editor (license 1.7) server-side columns search

Editor (license 1.7) server-side columns search

fmshighcompanyfmshighcompany Posts: 11Questions: 4Answers: 0

Hi!

I'm trying to get SERVER-SIDE column searching to work.

But when I search for something, it filters only on screen (not in entire database table).

Can anyone give some insight?

My SQL table has +250K records. I need to search by color, by reference, by price, etc.

My Editor license is 1.7.3. My Server-Side script uses EDITOR->class:

    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;

I used this example ( https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html ) to achieve COLUMN FILTERING.

        $('#Products thead tr').clone(true).appendTo( '#Products thead' );
        $('#Products thead tr:eq(1) th').each( function (i) {
            $(this).html( '<input type="text" />' );

            $( 'input', this ).on( 'keydown', function (ev) {
                if (ev.keyCode == 13) { //only on enter keypress (code 13) {
                    if ( ProductsTable.column(i).search() !== this.value ) {
                        ProductsTable
                            .column(i)
                            .search( this.value , true, false ) 
                            .draw();
                    }
                }
            } );
        } );

And the PHP script receives this POST when I type some search in PRODUCT_COLOR column: [white|blue]

 POST_Array
 (
     [draw] => 1
     [columns] => Array
         (
             [0] => Array
                 (
                     [data] => id
                     [name] =>
                     [searchable] => true
                     [orderable] => true
                     [search] => Array
                         (
                             [value] =>
                             [regex] => false
                         )

                 )

             [1] => Array
                 (
                     [data] => product_name
                     [name] =>
                     [searchable] => true
                     [orderable] => true
                     [search] => Array
                         (
                             [value] =>
                             [regex] => false
                         )

                 )
             [2] => Array
                 (
                     [data] => product_color
                     [name] =>
                     [searchable] => true
                     [orderable] => true
                     [search] => Array
                         (
                             [value] => white|blue
                             [regex] => true
                         )
                 )
         )

     [order] => Array
         (
             [0] => Array
                 (
                     [column] => 0
                     [dir] => desc
                 )

         )

     [start] => 0
     [length] => 18
     [search] => Array
         (
             [value] =>
             [regex] => false
         )

 )

Answers

  • fmshighcompanyfmshighcompany Posts: 11Questions: 4Answers: 0

    Forget about! Everything is ok!

    I inadvertently pressed F5 on the page, that reloaded, then the search input fields in the columns came out empty, but the filters remained active.

    Because of the setting: "stateSave : true"

    So... How do I initialise correctly those search input fields with the values saved in "stateSave" ?

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Hi,

    Good point this and you aren't the first to come across it. Have a look at the first comment in this example to see how it might be done. A similar approach can be taken for input elements.

    Allan

This discussion has been closed.