ServerSide Searching - Example

ServerSide Searching - Example

cbasmadjiancbasmadjian Posts: 56Questions: 14Answers: 0

Having a little trouble understanding how to filter my results from server side.processing.

If I use this example to send custom variables to the server: https://datatables.net/examples/server_side/custom_vars.html

The data that I want to filter is on one table. Can you link me to an example on how to run where clauses?

With the example from that link supposed I wanted to be able to search positions along with min and max salary. How would I do that on my server side? I just don't know how to run custom queries.

Hopefully, this question makes sense.

Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    What script are you using for the server-side processing? Have you written your own, or are you using Editor or SSP class?

    Allan

  • cbasmadjiancbasmadjian Posts: 56Questions: 14Answers: 0

    Great question Allan.

    This site is using a very simple editor script. This example very closely resembles it.

    https://editor.datatables.net/examples/simple/server-side-processing.html

    The slight difference is I don't use validators. It's just fields listed. Again very simple script so far.

    Does that help? How do I filter the results?

    Thanks!

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Please clarify:
    Are you using the DataTables Editor, or have you written your own?
    Are you using the DataTables SSP class, or have you written your own?

  • cbasmadjiancbasmadjian Posts: 56Questions: 14Answers: 0

    Hi Tangerine,

    Not sure what the difference is between editor, custom (something I built with editor), ssp, or custom (something I built with ssp). Sorry I am unable to answer that specifically.

    Last year I have purchased an Editor license if that helps?

    Maybe this might help, I am basically using this example's server side script, https://editor.datatables.net/examples/simple/server-side-processing.html

    If you look at the server side script tab this is the code that shows. My script is almost identical to this...

    <?php
     
    /*
     * Example PHP implementation used for the index.html example
     */
     
    // DataTables PHP library
    include( "../../php/DataTables.php" );
     
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
     
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'datatables_demo' )
        ->fields(
            Field::inst( 'first_name' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'last_name' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'position' ),
            Field::inst( 'email' ),
            Field::inst( 'office' ),
            Field::inst( 'extn' ),
            Field::inst( 'age' )
                ->validator( 'Validate::numeric' )
                ->setFormatter( 'Format::ifEmpty', null ),
            Field::inst( 'salary' )
                ->validator( 'Validate::numeric' )
                ->setFormatter( 'Format::ifEmpty', null ),
            Field::inst( 'start_date' )
                ->validator( 'Validate::dateFormat', array(
                    "format"  => Format::DATE_ISO_8601,
                    "message" => "Please enter a date in the format yyyy-mm-dd"
                ) )
                ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
                ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
        )
        ->process( $_POST )
        ->json();
    

    The only difference between that example and mine is I don't use the following, validator, getFormatter, and setFormatter.

    It's just the Fields of my table and that is it. Very simple.

    One thing I do not know how to do and if you would be so kind is to tell me (or link me?) to how to put where clauses because I am using the serverSide processing and the server will be doing the heavy lifting for my search results.

    So using the same example from "server side processing example", I want to be able to search min/max salary and min/max date. I just don't know how to do this.

    Is this making sense? Again, I am following very closing to that example I linked so if that example is using SSP, Editor, or some sort of variation then that might be able to answer your question.

    Hope this helps and looking forward to some guidance on how to filter some results!

    Thanks!

    P.S. All data is coming from one table from the DB. So if you suggest join's can you show me (or link me) how to do that with one table?

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Thanks - you are using Editor's PHP libraries. Perfect - the documentation for how to provide your own WHERE conditions is available here.

    Allan

This discussion has been closed.