No update after create/edit a table
No update after create/edit a table
Hi,
i have the problem that the table will not update after i create a new or edit an existing row. I did this a hundred times and it worked Always fine. I have no clue why it won't work now on this specific case. After pressing F5 in the browser all datas appeared as it should be.
I have to use two leftjoins, perhaps this is the error?
The Ajax part:
// 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,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, TB_MADB_TZUG, C_ZG_ID )
->debug( TRUE )
->fields(
Field::inst( TB_MADB_TZUG.'.'.C_ZG_NT, 'ntlogin' ),
Field::inst( TB_MADB_TZUG.'.'.C_ZG_YEAR, 'jahr' ),
Field::inst( TB_MADB_TZUG.'.'.C_ZG_DAYS, 'tage' ),
Field::inst( TB_MADB_TZUG.'.'.C_ZG_TYPE, 'art' ),
Field::inst( TB_MADB_TZUG.'.'.C_ZG_REMARK, 'remark' ),
Field::inst( 'A5_LANGUAGE_SET.LS_TRANS', 'ua_key' )
)
->leftJoin ('A5_VACTYPE', 'A5_VACTYPE.UA_ID', '=', TB_MADB_TZUG.'.'.C_ZG_TYPE)
->leftJoin ('A5_LANGUAGE_SET', 'A5_LANGUAGE_SET.LS_NAME', '=', 'A5_VACTYPE.UA_KEY')
->where(TB_MADB_TZUG.'.'.C_ZG_NT, $nt)
->where('A5_LANGUAGE_SET.LS_LG_ID', 1)
->process( $_POST )
->json();
The js part:
$(document).ready(function() {
// Editor
editor = new $.fn.dataTable.Editor( {
ajax: "ajax/tzug.php",
table: "#set_tzug",
fields: [ {
label: "Jahr",
name: "jahr",
type: "text"
},{
label: "Tage",
name: "tage",
type: "text"
},{
label: "Art",
name: "art",
type: "select",
options: [
<?php
for ($i = 0; $i < $mypos; $i++)
{
echo "{ label: '" . $tzugArten[$i]['tz_nam'] . "', "
. "value: " . $tzugArten[$i]['tz_id'] . " },\n";
}
?>
],
placeholder: "Bitte T-Zug wählen"
},{
label: "Bemerkung",
name: "remark",
type: "text"
},{
type: "hidden",
name: "ntlogin",
default: "<?php echo $row->ntlogin; ?>"
}
]
} );
// DTables
$('#set_tzug').DataTable({
"dom": '<"top"B>rt<"bottom"ip><"clear">',
serverSide: false,
"processing": true,
"order": [[0, 'asc']],
"pageLength": 12,
"ajax": {
"url": "ajax/tzug.php",
"type": "POST",
data: { mant: '<?php echo $row->ntlogin; ?>' }
},
select: true,
columns: [
{ data: "jahr" },
{ data: "tage" },
{ data: "ua_key" },
{ data: "remark" }
],
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
});
} );
Any idea where i have to look closely?
This question has accepted answers - jump to:
Answers
Hi @dg_datatables ,
What's changed since it did work? Did you change the DB, or server-side scripts, or has the client software been updated in any way?
Cheers,
Colin
Hi Colin,
no nothing was changed. I've have around 10 projects which use datables. This is an existing project. It's only expanded for a new table. The other tables in this project are working correctly - so all dependencies and scripts are available. I do not get any error message in the console or on the website.
Once again: Everything works. I can see all datas, i can sort or search the datas. But when i edit an existing row, after i press the "update" button the row disappeared in the table. When i reload the page the edited row appears with the correct (edited) datas.
The same after i insert a new row. After the insert the new row does not appeared on the screen. After a refresh of the website, the new row is showed.
Thanks for your help
Christian
Hi @dg_datatables ,
If it's appearing after a refresh, it's likely to be something to do with the response from the server. Can you post the message the server sends back in respond to the create please. And you might as well post the message to the server as well for completeness!
Cheers,
Colin
This is send to the server:
and this is the response:
The data appears only after a refresh.
data
is an empty array. It should contain the data for the newly added row.It looks like you have a WHERE condition. Does the newly added row match that? my guess is not.
Allan
I will doublecheck this. But why do i see it after a refresh?
Hi @dg_datatables ,
It's because the response determines how the table is redrawn after the submission. The submission succeeds, the data is there, but if the response isn't as expected then Editor doesn't redraw the table with the new data. The refresh works because it gets all data afresh.
Cheers,
Colin
@allan
You were absolutly right - like always ;-)
After an edit/new action the variable $nt is empty and the where-condition could not be passed. I put the $nt into a $_Session and everything works fine.
Just for me to know:
How can i read the value of the hidden field from the editor in the ajax part?
Hi @dg_datatables ,
If it's hidden, you can still access the column with
row().data()
. Hope that helps,Cheers,
Colin
@colin
No, i mean a hidden field from the editor pop up.
If i have a editor like in the example (see below). How can i get access to the hidden field "secret" im my ajax? I want to manipulate the where statement with the hidden field from editor.
I'd actually suggest you do this:
Then you can just do
$_POST['secret']
to get the value. That assumes that you don't want to do the value of a per row basis though.If you do want to do it on a per row basis, then keep your
hidden
field and use a server-side event. The data for the row to be processed is passed into the event handler. That has the benefit of working with multi-row editing as well.Allan
Great! Thanks a lot.