updating json with values after posting
updating json with values after posting
Hi Allan,
After processing POST the following code is used to get json for updating select field in client side
[code]
if ( !isset($_POST['action']) ) {
$out['schoolsList'] = $db
->select( 'schools', 'id as value, school_name as label' )
->fetchAll();
}
// Send it back to the client
echo json_encode( $out );
[/code]
I am using this json like this
[code]
"fnInitComplete": function ( settings, json ) {
editor.field('schools.id').update( json.schoolsList );
}
[/code]
It works well initially, but even after changes made by editor and db values changed, the option values and json values does not reflect these changes. Until the whole page is reloaded.
Let me know your suggestion please.
After processing POST the following code is used to get json for updating select field in client side
[code]
if ( !isset($_POST['action']) ) {
$out['schoolsList'] = $db
->select( 'schools', 'id as value, school_name as label' )
->fetchAll();
}
// Send it back to the client
echo json_encode( $out );
[/code]
I am using this json like this
[code]
"fnInitComplete": function ( settings, json ) {
editor.field('schools.id').update( json.schoolsList );
}
[/code]
It works well initially, but even after changes made by editor and db values changed, the option values and json values does not reflect these changes. Until the whole page is reloaded.
Let me know your suggestion please.
This discussion has been closed.
Replies
Allan
As you told i got back school list information after edit action. I was trying to update using in side editor events. but it gives a null out put.
[code]
"events": { "onInitEdit": function ( settings, json ) {editor.field('schools.id').update( json.schoolsList);
[/code]
When I tried to use it like this, it says that json is undefined.
[code]
editor.on('onInitCreate onInitEdit', function ( settings, json ) {editor.field('schools.id').update( json.schoolsList);
[/code]
Please let me know where I am going wrong.
Or else, is there any function simlar to "fnInitComplete": to be used in .dataTable.
fnInitComplete is a DataTable init function, so I don't understand why you would want a similar one?
I don't know what is going wrong here, because I still don't really understand what you are trying to do. Please link to a test case with clear steps on how to reproduce the issue.
Allan
[quote]allan said: still don't really understand what you are trying to do.[/quote]
I am trying to change the options for a editor field using the json data. It works well when the data table is initialised. But after creating/editing/deleting the the field options should change according to new value of database. Hence json created accordingly and sending the schoolsList information back with all requests. But i m not able to update field with new json data using the above methods.
Hope you have a solution for it, Thanking you.
Allan
I have new data set to update as part of ajax call after each create /edit/delete actions
[code]
$out =$editor
->process($_POST)
->data();
$out['schoolsList'] = $db
->select( 'schools', 'id as value, school_name as label' )
->fetchAll();
echo json_encode( $out );
[/code]
but i could not use this new data set in editor instance.
Allan
editor.on('onPostEdit', function ( settings, json ) {editor.field('schools.id').update( json.schoolsList);})
[/code]
should work, right? any modification required?
Allan