construct Datatable ajax response programmatically
construct Datatable ajax response programmatically
malpauti
Posts: 8Questions: 4Answers: 1
I'm attempting to recreate the following in PHP dynamically:
Editor::inst( $db, 'user_to_groups')
->field(
Field::inst( 'user_to_groups.user' ),
Field::inst( 'user_to_groups.group' )
->options( Options::inst()
->table('groups')
->value('ID')
->label('groupname')
)
->validator( 'Validate::dbValues' ),
Field::inst( 'groups.groupname' )
)
->where('user',25)
->leftJoin( 'groups', 'groups.id', '=', 'user_to_groups.group' )
->process($_POST)
->json();
So far, my attempt has yielded:
$editor = new Editor( $db, $tablename, $tablekey );
$editor->fields(new Field("user_to_groups.user"));
$editor->fields(new Field("user_to_groups.group"));
$editor->fields(Field("user_to_groups.group"))->options( 'groups','ID','groupname' );
$editor->fields(Field("user_to_groups.group"))->validator( 'Validate::dbValues' );
$editor->fields(new Field("groups.groupname"));
$editor->where('user','25');
$editor->leftJoin( 'groups', 'groups.id', '=', 'user_to_groups.group' );
$editor->process( $_POST ) ->json();
I think the first 3 lines are correct. Can you please provide guidance on correct syntax for setting options, validator, and joins?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
My answer is based on using DataTables and Editor client side. Server-side requires a bit more work.
You are free to make your own server part. You only have to respect 2 things:
Receiving request from the clients can be separated in 2 kinds:
Regarding the first, there are 4 options:
It may look a little bit complex, but believe me, as soon as you understand how the things are working it is easy going and giving a lot more flexibility in validating input, using multiple languages etc...
I can give you some examples if you need, but you have to understand that I am using the CodeIgniter Framework and all my work was done inside this framework. I can not give examples of other frameworks.
Here you can find more information about the data used between client and server: https://editor.datatables.net/manual/server
Here an example of how to process AJAX requests:
My specific challenge is the creation of the DataTables Editor object server-side in php. Appreciate your prompt response but it has not helped.
The nesting is slightly wrong - for example:
Should be:
i.e. the
validator
belongs to theField
. Also you need to usenew
for the field like in the other ones.Its perhaps a little easier to see with newlines:
Allan