More checkbox editor examples for trial evaluation purposes

More checkbox editor examples for trial evaluation purposes

tonyaldotonyaldo Posts: 13Questions: 2Answers: 0
edited January 2019 in Free community support

I started evaluating editor for a small requirement I have but I am not so sure it can be done without changing the underlying data structure

This example https://editor.datatables.net/examples/advanced/joinArray.html is closest to what I am looking for

User selects the row, clicks edit and can checkbox up to 3 options Email, SMS, Call
What is displayed however is based on the enabled field in the JSON

DataTables table is able to render the column correctly with simple { data: "notification.enabled" }
The editor however will not render the checkboxes with the editor fields initialization options below.

Any ideas if this is supported in datatables editor ?

            {
              label: "Notification:",
              name: "notification.options",
              type: "checkbox"
            },
//Data source

[
{
    "notification": {
        "enabled": ["Email"],
        "options": ["Email", "SMS", "Call"]
    },
    "_id": "5c2bab964d83ef7b06599621",
    "name": "Doyle Gerlach IV"

}, {
    "notification": {
        "enabled": ["Email"],
        "options": ["Email", "SMS", "Call"]
    },
    "_id": "5c2bab964d83ef7b06599620",
    "name": "Keagan Batz"
}
]

Answers

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    Can the options be different for each row? If so you'd need to update the list of options available as each row is edited - that could be done with initEdit and the field().update() method of select.

    For example:

    editor.on( 'initEdit', function ( e, node, data, items, type ) {
      editor.field( 'notification.options' ).update( data.notification.options );
    } );
    

    Allan

  • tonyaldotonyaldo Posts: 13Questions: 2Answers: 0
    edited January 2019

    Options will be identical for each row. Enabled will always be a subset.

    Field below does not render the checkbox. It is not clear from examples if anything extra is needed.

                {
                  label: "Notification:",
                  name: "notification.options",
                  type: "checkbox"
                },
    

    DataTables wise however the column is being rendered correctly with

    "columns": [
              { data: "name" },
              { data: "notification.enabled" }
            ]
    
  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    You need to set the options for the field using the field().update() method like I suggested above. If the options are static, then you could simply use:

    editor.field('notification.enabled').update( [
      "Email", "SMS", "Call"
    ] );
    

    Note also that since you want to edit the value of the enabled array, you should use:

    name: 'notification.enabled'
    

    in your Editor field definition.

    Allan

  • tonyaldotonyaldo Posts: 13Questions: 2Answers: 0

    This is brilliant. So probably means notification.options isnt even needed. Many thanks
    Curious if you have a roadmap for editor published somewhere ? Would be keen to look at upcoming features and if there are plans to loose jquery as a dependancy

This discussion has been closed.