Stay in the page than contains the record I modify

Stay in the page than contains the record I modify

jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
edited June 2013 in Editor
Hi Allan.
When I modify a record via Editor and press Update, always send my dataTable to the first page. How can I stay in the page that include my record ?
I looked for in forums but I can´t find a solution.

Thanks

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    This is caused by the call `dt.fnDraw();` on line 2855 in the Editor library. If you modify that to be `dt.fnDraw( false );` that will keep the current paging.

    I'm going to add this ability as a feature in the next release of Editor, which will be building upon the DataTables 1.10 API, which has much better control of holding the page static.

    Regards,
    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    It could be the line 2837 in Datatables 1.9.4 ?
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Actually, my apologises - I was looking at the delete draw there. The code you are looking for is `dt.fnUpdate( setData, that.s.editRow );` in Editor (line 2834 in Editor 1.2.2). You could change it to: `dt.fnUpdate( setData, that.s.editRow, undefined, false );` . However, be aware that your new data won't be sorted or filtered until you do a full redraw.

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Hi
    I use dataTables.editor.js version 1.2.3.
    The line you mention is 2856, but with this change it doesn,t works.
    With the first modification : dt.fnDraw( false ) in line 2837

    if ( dt.fnSettings().oFeatures.bServerSide ) {
    // Regardless of if it was a new row, an update or an delete, with
    // SSP we draw the table to refresh the content
    dt.fnDraw(false);
    }

    But I am not secure enough if this is correct.
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    I mean that with dt.fnDraw(false) in line 2837 works. I dont know if it has collateral efects.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Are you using server-side processing? The block you indicate above will only execute if you are.

    It sounds like you might actually be best off waiting for the next release which will have this ability built in. Although I am surprised that the change to fnUpdate didn't work.

    Are you able to link me to the page so I can take a look at what is happening?

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    I send you the link by mail. It´s not secure enough. Sorry.
  • AKM3AKM3 Posts: 9Questions: 0Answers: 0
    Hello Allan,
    your code: dt.fnUpdate( setData, that.s.editRow, undefined, false );

    Works and keeps the current page when you Edit an existing row.

    For my particular project, where I just need to show last page, I added this line:
    [code]
    if ( dt.fnSettings().oFeatures.bServerSide ) {
    dt.fnDraw();
    }
    else if ( that.s.action === "create" ) {
    // New row was created to add it to the DT
    if ( that.s.idSrc === null ) {
    setData.DT_RowId = json.id;
    }
    else {
    setFn = dt.oApi._fnSetObjectDataFn( that.s.idSrc );
    setFn( setData, json.id );
    }
    that._callbackFire( 'onPreCreate', [json, setData] );
    dt.fnAddData( setData );
    //Added go to last page after inserting
    dt.fnPageChange( 'last' );
    that._callbackFire( ['onCreate', 'onPostCreate'], [json, setData] );
    }
    [/code]

    However I would like to keep this changes away of your editor code. Is there any way to put an external "on create" function that triggers on a successful editor insert ?
    Thank you very much for all the guidance
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > Is there any way to put an external "on create" function that triggers on a successful editor insert ?

    Yes indeed - on the next line of code you'll see the onCreate and onPostCreate events that Editor fires. So you could do:

    [code]
    editor.on( 'onCreate', function () {
    table.fnPageChange( 'last' );
    } );
    [/code]

    i.e. listen for the event and act upon it when it occurs.

    Allan
This discussion has been closed.