Editor API: provide a query

Editor API: provide a query

aaplmikeaaplmike Posts: 6Questions: 2Answers: 0

Hello, how can I provide a customized query when invoking the API? I only need to present a subset of a large database based on a particular field (userid, for example). In the examples, Editor just returns and displays all records in the database provided. It looks like I can filter on the client side, but if I have 12 million rows in the DB, I'd rather not have to download all of them each time the user visits the page.So, I'd like to send a query

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,302Questions: 26Answers: 4,947

    There are a few options that come to mind:

    1. Server Side Processing
    2. The ajax.data option to send the parameters
    3. Use an external ajax call with the data option and in the success function add the data to the Datatable using rows.add()

    Kevin

  • aaplmikeaaplmike Posts: 6Questions: 2Answers: 0

    Thanks, Kevin.

    Is there any way to incorporate this into the PHP Editor class (DataTables.php)? In the example I have, the data is fetched (and put?) via:
    Editor::inst( $db, 'mytable', 'id)
    ->fields( /* validations here */ )
    ->process($_POST)
    ->json();

    I do want to make use of the validators in the class, but want to provide a query such as SELECT * FROM mytable WHERE uid=100 to limit what data I pull in from the DB.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Editor's PHP libraries support server-side processing out of the box. Typically you just need to add serverSide and use the ajax option (ajax.type specifically) to sent the DataTables request as a POST rather than GET.

    You can also provide conditions with the Editor PHP libraries.

    Allan

  • aaplmikeaaplmike Posts: 6Questions: 2Answers: 0

    I think I found what I was looking for using Editor's where() method. Thanks, all.

This discussion has been closed.