Editor API: provide a query
Editor API: provide a query
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
There are a few options that come to mind:
ajax.data
option to send the parametersdata
option and in the success function add the data to the Datatable usingrows.add()
Kevin
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.Editor's PHP libraries support server-side processing out of the box. Typically you just need to add
serverSide
and use theajax
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
I think I found what I was looking for using Editor's
where()
method. Thanks, all.