Error on update and add actions when using generator

Error on update and add actions when using generator

tknoptknop Posts: 14Questions: 0Answers: 0
edited December 2013 in Editor
Hi,

I just purchased the Editor License. Really great plugin by the way.
However, i encounter some issues to use it, and i really don't understand what i'm doing wrong.

Unfortunately, i can't provide link to the app, since it requires credentials.
However, here is the report from the debug tools : http://debug.datatables.net/utelus

Here is my first problem :

When adding, updating a row in my datatable, i've got error messages.

For update actions, i got a pop-up with : "DataTables warning (table id = 'datatable'): Requested unknown parameter '0' from the data source for row 70". When i close the pop-up, then the content of the updated row disappears from the datatable, but i still see an empty row. This problem is independent of the row i choose to update. I precise that the row has actually been updated, since when i reload the table, the modified information appears.

For add actions, the form does not close and when analyzing with firebug, here is the answer from the server :
"b>Notice: Undefined offset: 0 in /homez.361/lsmcup/www/manager/tools/lib/Editor/Editor.php on line 507

{"id":"row_0","error":"","fieldErrors":[],"data":[],"row":null}". However, the new entry has correctly been added to my database.

Here are the relevant parts of my code :

[code]
<?php

/*
* Editor server script for DB table participants
* Automatically generated by http://editor.datatables.net/generator
*/

// DataTables PHP library
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;


// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'participants', 'ID' )
->fields(
Field::inst( 'ID' )
->validator( 'Validate::required' ),
Field::inst( 'teamName' )
->validator( 'Validate::required' ),
Field::inst( 'email' )
->validator( 'Validate::email_required' ),
Field::inst( 'challenger1' )
->validator( 'Validate::required' ),
Field::inst( 'studies1' )
->validator( 'Validate::required' ),
Field::inst( 'university1' )
->validator( 'Validate::required' ),
Field::inst( 'studyyear1' )
->validator( 'Validate::required' ),
Field::inst( 'challenger2' )
->validator( 'Validate::required' ),
Field::inst( 'studies2' )
->validator( 'Validate::required' ),
Field::inst( 'university2' )
->validator( 'Validate::required' ),
Field::inst( 'studyyear2' )
->validator( 'Validate::required' )
)
->process( $_POST )
->json();
[/code]


[code]




Name
E-mail
Player 1
Study
University
Year
Player 2
Study
University
Year






$(function() {
var oTable;
var editor;
var aSelected = [];
var spath = window.location.search.split("&"), i;
var id = -1;
for(i=0; i

Replies

  • tknoptknop Posts: 14Questions: 0Answers: 0
    I'd really appreciate if someone could help me with this. I'm really stuck at the moment...
    Thanks!
  • allanallan Posts: 61,683Questions: 1Answers: 10,100 Site admin
    Hi,

    Sorry for the delay in replying, as noted else where in the forum I've been traveling this week.

    Looking at the code above and the debug trace (thanks for them), it doesn't look like you are providing the `DT_RowId` parameter - so my question is, who does the server-side script know which row is being edited in the database? By default DataTables and Editor use `DT_RowId` , which is the value of the primary key, to know which row is being updated, deleted etc - without that, it can't automatically identify each row. Normally, using Ajax loaded data from the Editor PHP scripts, this would happen automatically, but it looks like you are populating data from Javascript, rather than from Ajax. That's fair enough, but I'd recommend adding the `DT_RowId` parameter like in all the examples, or using an event such as onPreSubmit to send the required ID information to the server.

    Allan
  • tknoptknop Posts: 14Questions: 0Answers: 0
    Hi Allan,

    Thanks for your answer. However, i'm not sure i get it. Isn't [code] 'idSrc': 'ID', [/code] enough to replace the DT_RowId by my primary key and tell the server-side script which row is being edited ?

    I'm not sure to understand where i have to add the DT_RowId parameter. I looked at the exemple (here online), but i still don't understand. Should i change the name of my first column to DT_RowId and make it my primary key in my db ? In the other exemple, it is never the case...

    Thanks for your help,
  • allanallan Posts: 61,683Questions: 1Answers: 10,100 Site admin
    > 'idSrc': 'ID',

    Urgh - I missed that. Yes that should be enough. Sorry!

    In which case, I'm afraid I'm not actually sure what is going wrong with the code above. Are you able to PM me the details to be able to login to the app and see the error actually occurring?

    Thanks,
    Allan
  • allanallan Posts: 61,683Questions: 1Answers: 10,100 Site admin
    Ah - I see what is happening.

    You are loading the data for the table from the HTML directly, rather than loading it from the Ajax source. When setup like this, DataTables will read the data into an array. However, the Editor PHP scripts return objects - thus there is a discrepancy and thus the error.

    You basically have two options:

    1. Ajax load the data for the table through the Editor libraries
    2. Modify the libraries to return arrays rather than objects.

    Personally, I'd pick option 1 :-)

    Allan
  • tknoptknop Posts: 14Questions: 0Answers: 0
    Thanks Allan, I'll try this when i get some time :)
This discussion has been closed.