Standalone edition : edit() by id

Standalone edition : edit() by id

sdroulerssdroulers Posts: 43Questions: 14Answers: 0

Hi,

I'm looking for a way edit a specific record (lets says with id #7) by clicking on a link (there is no table on my page).

I closely read the following from the edit() documentation:

Standalone editing - Not required. Standalone editing cannot use multiple form sources like DataTables editing, a single Editor instance refers to a single configuration set in the database, so this option is not required, however, it can still be provided to give identification information to the server. Whatever value is given here will be passed to the server as the id parameter. Use null if you want to provide the other parameters (show and options) and do not require a value to be given.

So, to my understanding I could do such thing in js as :

non_conformity_editor.edit(7)

and it would edit record with id #7? Actually it opens the editor modal but with empty records.

Many thanks!

Sébastien

This question has accepted answers - jump to:

Answers

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0

    Well,

    there must be something I missed in my understanding on how things work.

    I tried doing so:

    non_conformity_editor.edit('row_7')
    

    and actually everything works.

    I'll some more docs to understand why!

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Hi Sébastien,

    It will need edit row id 7 (assuming the server-side script is setup to handle the request). However, if the form in the data is showing as empty, that suggests that the field values are not already present in the HTML for the form to display.

    If you look at this example you will see that the values are in the HTML. Editor does not make an Ajax request to get the values based on the row id.

    Allan

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0
    edited January 2018

    Hi Allan,

    as always, many thanks for your answer.

    I worked this afternoon on this to try to find a good solution that matches my needs but I'm kind of stuck in my process

    My actual situation is the following:

    • I have two tables, the "product" table and the "issues" table --> OK
    • My "product" editor instance shows me general infos about a product and in a div
      a list of issues related to this product (stored in the "issues") table --> OK
    • I managed to have a nested editor instance that shows up a second modal to create new "issue" records --> OK
    • now what I'm trying to achieve is the ability to "edit" a specific record if I click on it from the "product" editor window --> this is where I am stuck

    My problem is that my "issue" table is not displayed on my page when I work on products and therefore I can not access it (or its data) from my "product" editor window (what I mentioned as success was a bug displaying the two tables on the same page).

    I made a specific Ajax request to get the "issue" records related to a specific product:

    {"data":[{"DT_RowId":"row_7","id":"7","product":"0728 - 1","date":"09\/01\/2018 22:07","non_conformity_quantities":"100"},{"DT_RowId":"row_8","id":"8","product":"0728 - 1","date":"09\/01\/2018 22:07","non_conformity_quantities":"200"}]]

    but from there I'm stuck with mixed feelings wondering if I don't have it all wrong.

    Thanks again

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Answer ✓

    If you don't have the data you want to edit already on the page - that's fine, but you do need to an extra step. You've loaded the data, so what you can do is use the Editor API to set those values (val()) - for example you might do:

    editor
      .edit( 7 )
      .val( 'product', data.product )
      .val( 'date', data.date )
      ...
      .title( 'Edit' )
      .buttons( 'Save' );
    

    Allan

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0

    Just b r i l l i a n t ! B)

    Many thanks

This discussion has been closed.