Editor: Passing RowIds explicitly into Edit Multiple Form with AJAX

Editor: Passing RowIds explicitly into Edit Multiple Form with AJAX

nick_psnick_ps Posts: 12Questions: 3Answers: 0

I have successfully implemented Datatables with Rails using AJAX to pass data for each Datatable page. The row selections are tracked using a selected_row_ids[] array that gets updated on each row select and deselect. The row_ids are sent to the server for a variety of actions. It all works well.

However, when using the Editor button for editing multiple selections, I can't find how to pass the selected_row_ids[] into the Editor Edit Multiple form. At the moment, only rows from the current page are passed into the Edit Multiple form. How would you pass the selected_row_ids from multiple pages into the edit form, in an AJAX ?

Can it be done here, with something naive like this?

buttons: [ { extend: "edit", editor: editor, rowIds: selected_row_ids } ]

Thanks,

Nick

Replies

  • nick_psnick_ps Posts: 12Questions: 3Answers: 0

    And to make it clearer:

    If a user has selected one row on page one, and moves onto selecting one row on page 2, (so there are 2 RowIds selected and stored in selected_row_ids[ ] ), how do I tell the editor there are 2 ids/rows selected?

    Because, from Datatables Editor AJAX perspective there is only the subset of page 2 rows loaded and only one row on page 2 selected.

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

    From your description, I presume you are using server-side processing (serverSide)? If so, the DataTable can't be used as the data source for the form, since as you note, the data for the page that isn't visible cannot be used (it isn't present on the client-side). Instead, what you would need to do is load the data for the rows being edited through the setMulti() method (i.e. query the database and get the data for the rows being edited).

    Or, if you have less than around 50k rows in the table, disable server-side processing.

    Allan

  • nick_psnick_ps Posts: 12Questions: 3Answers: 0

    Thanks for your help, Allan.

    Unfortunately, we can't disable server-side processing on this particular App.

    I've got the server returning data in the format required by multiSet() via an Ajax call as suggested. A simplified example with fields and the table row_ids:
    edit_multiple_data = {"number":{"52398":"A01","52399":"A02"},"dt_archive":{"52398":"0","52399":"0"}}

    Now I want to pass that information into the the Multi-Edit Form.
    editor .edit(table.rows({ selected: true }).indexes()) .multiSet(edit_multiple_data);

    When I do this with 2 table rows selected i get an error: Unknown field name - undefined.

    If there is only 1 table row selected, an edit box with no fields is rendered.

    I've scoured the documentation, and I can't find much on this. Any pointers on getting the server data to register as multiple values in the edit form field?

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

    .edit(table.rows({ selected: true }).indexes())

    This isn't going to work unfortunately since that is only going to pick the rows which are selected on the current page and not trigger editing on anything else. I actually think the only way to get server-side processing working with editing rows which are not on the current page is to have the server store all selected rows, and when editor is triggered (as a standalone) then populate the instance. This is something I'm struggling with for CloudTables as well!

    That said - I don't know why you are getting the Unknown field name error - are you able to give me a link to a page showing the error so I can check that (although I'm not sure that solving it is going to help fix the bigger issue!).

    Allan

  • nick_psnick_ps Posts: 12Questions: 3Answers: 0

    Thanks again Allan!

    Focusing on the big picture, in this case the server knows each of the selected rows.

    Could you please unpack, “when editor is triggered (as a standalone) then populate the instance”.

    What do you mean by ‘as standalone’? And, how to populate the instance?

    In my naive reasoning, it would be great if the following was possible:
    - create an edit form without selection (or overridable selection)
    - pass in data for each field
    - If multiple values render multi-data field
    - Store row_ids (from selected or ids passed in from server)
    - regular edit form renders
    - datatables carries on in regular way

    All we would need is the ability to instantiate an edit form, and pass in data without selecting rows.

    (“All we would need”, is probably more complicated than I imagine! :) )

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

    Editor's standalone mode is largely decoupled from DataTables. It is activated when there is no table option in the Editor constructor configuration.

    Code is probably worth a whole essay here, so here is an example of using standalone editing: http://live.datatables.net/jorutoji/7/edit . I've got it client-side only due to the limitations of the live example, but have commented where the Ajax call would be needed, etc.

    Allan

  • nick_psnick_ps Posts: 12Questions: 3Answers: 0

    Thanks Allan.

Sign In or Register to comment.