How to handle a JSON object with bubble, inline or standard edit

How to handle a JSON object with bubble, inline or standard edit

Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

I'm using an ajax data source for my data, and as a straight up datatable it's working well.
There are 4 (or more) columns, the first 3 being simple name, description and idsrc (tells me which competition round, competitor and item we are looking at added for editor).

None of these I wish to edit. But the rest of the ortions are 'scores'. One for each judge.
For simplicity lets assume there's always only 1 judge.

The data object looks something like this:

[  
   {  
      "num":1,
      "fig":"Sharks Tooth",
      "S1J1":{  
         "figureNum":1,
         "scoreTime":1563826061,
         "breakFlag":0,
         "score":5,
         "comment":"Out of bounds"
      },
      "idsrc":"1:1:1"
   },
   {  
      "num":2,
      "fig":"Tear Drop",
      "S1J1":{  
         "figureNum":2,
         "scoreTime":1563826061,
         "breakFlag":0,
         "score":4,
         "comment":null
      },
      "idsrc":"1:1:2"
   }
]

I am rendering the S1J1 column with a custom render function in DT, but when I try and edit these (in an inline) the editor renders the object as a String. That makes sense.

How can I define the fields of Datatables Editor such that I can edit not only the score, but also the other options (breakFlag and comment in particular.

I guess I am looking for Editor's 'render' equivalent...

This question has an accepted answers - jump to answer

Answers

  • Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

    I wonder if the only way to do this with Editor would be to create a custom field type plugin that handled JS objects...

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin

    You could do this with multiple fields in a bubble edit:

    fields: [
      { label: 'Figure', name: 'S1J1.figureNum' },
      { label: 'Break flag:', name: 'S1J1.breakFlag' },
      ...
    ]
    

    Then use:

    editor.bubble( this, [ 'S1J1.figureNum', 'S1J1.breakFlag', ... ] );
    

    That won't work with inline editing as inline editing is only capable of showing a single field at a time I'm afraid.

    My curiosity gets the better of me - what is "breakFlag"? :)

    Allan

  • Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

    Hello Allan,

    Thanks for responding.

    I did consider splitting this up into multiple columns. The main reason for it to be in one is to keep the table concise.

    Does that mean I'd need to have an extra column for the DT itself? i.e. do the fields need to correspond to the columns?

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin
    Answer ✓

    No you can have multiple fields in a single bubble. Its only if you wanted to use inline editing would it need to be split into separate columns.

    Allan

  • Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

    Thanks Allan!

This discussion has been closed.