fnServerParams within Editor

fnServerParams within Editor

lowrymellowrymel Posts: 20Questions: 4Answers: 0
edited November 2013 in Editor
Hi All,

I have Parent - Child tables where I am using fnServerParams and reLoadAjax on the ParentTable to keep the relationship in synch. I am using fnServerParams to pass a value to the Child PHP file for a where clause (ie. where member_id = $member_key). These are fairly large tables ~5M rows. Everything is working great in dataTables. Any change of row in the Parent Table displays the appropriate subset of data in the child table. I can see the server parameter passed from fnServerParams in debug. Performance is very acceptable- ~30ms for each child table load.

Issue - generic updates to the Child Table via Editor are not seeing the server parameter member_key. The updates are actually getting through but the error is in the post back (I think). I am hoping (and expecting) that I am missing something really basic here.



if(isset($_POST['member_key'])){ $member_key = $_POST['member_key']; };

$out = $editor
->where( 'member_id', $member_key,'=' ) // error is here
->process($_POST)
->data();


Unfortunately I cannot provide a test at this time.

Any ideas?

Thanks in advance

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi,

    Editor doesn't share its Ajax options with DataTables at all, so if you want to send extra parameters you need to do it using the 'Editor way'. In this case, there are two options:

    1. Listening for the `onPreSubmit` event ( https://editor.datatables.net/options/#onPreSubmit ):

    [code]
    editor.on( 'onPreSubmit', function ( d ) {
    d.data.member_key = '...';
    } );
    [/code]

    2. Using a hidden field: https://editor.datatables.net/fields/#hidden . You'd just set the value that you want the field to be.

    Either method should work in this case I think - its whichever you prefer to use!

    Allan
  • lowrymellowrymel Posts: 20Questions: 4Answers: 0
    Thanks so much. This is amazing product!

    BTW, there is still an update bug 'Undefined offset: 0 in /datatables/lib/Editor/Editor.php'
    that was referenced on the bottom of http://datatables.net/forums/discussion/comment/48995

    however AKM3's fix is working fine.

    Thanks again.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Thanks for your kind words!

    Does it say what line number it is? That error can occur if the primary key has changed value - at least that's when I've seen it occur myself.

    Regards,
    Allan
  • lowrymellowrymel Posts: 20Questions: 4Answers: 0
    The error s being returned on row 517' _update( $id ) function in my code.
    What I found was the actual problem was higher at row 521 '$res = $this->_db->update( $this->_table, $set, array($this->_pkey => $id) )'; which was failing a string conversion.

    Again this occurred when using a where clause as in the following code snip. The commented code causes the error and the workaround is the current solution,.

    // workaround to fix Editor where update issue - http://datatables.net/forums/discussion/comment/48995
    if (!isset( $_POST['action'] )) $editor->where( 'member_id', $member_key,'=' );

    $out = $editor
    //->where( 'member_id', $member_key,'=' )
    ->process($_POST)
    ->data();



    Hope this helps.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Ah I see! So the where condition is excluding the data from the table when it has been updated - thus it doesn't find the data in the SQL select and the warning occurs.

    In this condition, would you expect the data to be removed form the table?

    Allan
  • lowrymellowrymel Posts: 20Questions: 4Answers: 0
    This was just a simply update using editor. So I would expect the table to be updated as it is with the workaround.
This discussion has been closed.