Datatables Editor - Select List Field Type, what kind of data should I send via Editor?

Datatables Editor - Select List Field Type, what kind of data should I send via Editor?

pekorpitpekorpit Posts: 7Questions: 3Answers: 0
edited February 2016 in Free community support

Hello, hopefully this is simple question.

I have Select List Field Type that I have initialized with options containing label + value pairs:

...
{"label":valueListItems.Item(i+1).Name, "value":valueListItems.Item(i+1).ID}
...
{ "label":propertyDefName, name:pd, type: "select", "placeholder": "...", options: selectionList, multiple: true }

Selection list content is correct in bubble editor, but it only seems to work if I have selected only 1 value from the list, and even then table shows numbers (value) instead of label of selection.

When I get changed data from Editor and process it in ajax method (I am overwriting it to process data locally) data comes in form of: ..."pd1230":[81,31,92]...

Then send data onwards to system that stores data and I send updated values back to table in similar form before exiting ajax method: ..."data":[81,31,92]...

Sure enough it sort of works, but why numbers? What is data structure I should post to Datatables to make it show labels related to those values instead of those values? Also datatables does not really understand multiselect data in that form, as bubble editor does not have those values selected when I open it the next time. (For single selection it does correct selection, but shows numbers instead of labels in table before and after I make the selection.)

I hope my question makes sense!

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,192Questions: 1Answers: 10,412 Site admin

    Could you post the full Javascript you are using please - or ideally just a link ot the page.

    The table will show the numbers rather than a label if that is what it is instructed to do with columns.data. The data object that is loaded must contain both the label and the value (unless you want to specify your own look up function with a rendering function, which you can do if you want).

    Have a look at the data structure discussed in the PHP join manual for Editor (even if you aren't using the PHP libraries). It should give an idea of how the Editor examples approach this issue.

    Allan

  • pekorpitpekorpit Posts: 7Questions: 3Answers: 0

    Hi Allan!

    Thanks for resolving two other open questions, I took a look at render option for single and multiple select fields. Good thing that you mentioned it, but, but... I think question now boils down to:

    Single Select, ajax method now returns this kind of data:
    {"label":"foo", "value": 5}

    Multiple Select, ajax method now returns this kind of data:
    {"label":"foo;goo;doo", "value":[5,6,7]}

    Question I suppose is that how do I tell Field?/Column? to map contents of value with number or array of numbers to values in the list so that when I select next value with Bubble Editor correct values are shown as selected.

    From your previous post I gather that you mean that column data option should be something else than "data":"pd123" which works super great with single values, but not ok with select lists, yet.

  • allanallan Posts: 63,192Questions: 1Answers: 10,412 Site admin

    {"label":"foo;goo;doo", "value":[5,6,7]}

    I'm not quite understanding that - could you link to the page showing the issue please and post the PHP you are using. The option value is [5,6,7]? I would generally expect the option to be a scalar rather than a vector and the row's data might refer to multiple values.

    Allan

  • pekorpitpekorpit Posts: 7Questions: 3Answers: 0
    edited February 2016

    Hi Allan, I appreciate your help, I am not sure what to try next.

    I cannot link page as it is dynamically built and not run as part of hosted web page. Rather it is an extension UI that runs on local browser. Ajax is a local method where API to backend application is used to retrieve and update system data. No PHP is used.

    Data I get when execution comes to ajax method after doing selection with bubble editor:

    Single (i open select list, and select "foo"): "pd123":5

    Multi (i open select list, and select "foo" and "goo"): "pd124":[5,6]

    I changed single and multiple select list handling so that data that I return from ajax call after succesfull update of backend system is in array form (for unified handling):

    Example of single select data returned from ajax call:"pd123":[ {"label":"foo", "value":5} ]

    Example of multiple select returned from ajax call: "pd124":[ {"label":"foo", "value":5}, {"label":"goo", "value":6} ]

    I have defined columns like so (I removed actual render javascript as it just returns combined label text):

    Single: { "id": propertyDefId, "data": "pd" + propertyDefId, "title": propertyDefName, "visible": visible, "render": function ( data, type, full, meta ) {...} }

    Multi { "id": propertyDefId, "data": "pd" + propertyDefId/+"[]", editField: "pd" + propertyDefId/, "title": propertyDefName, "visible": visible, "render": function ( data, type, full, meta ) { ... } }

    I have defined editor fields like so:

    Single: { "label":propertyDefName, name:pd, "type": "select", "placeholder": "...", options": selectionList, "multiple": false }

    Multi { "label":propertyDefName, name:pd, type: "select", "placeholder": "...", options: selectionList, multiple: true }

    So I just would like to have selection list to have correct values selected based on data in table.

  • pekorpitpekorpit Posts: 7Questions: 3Answers: 0

    If having Datatables Editor to automatically map returned values to selection list labels proves overly complicated, with what operation of Datatables/Editor could I manually set correct labels to be highlighted when selection list bubble editor is opened? (I mean I do have lookups that I need to know at hand.)

    I would really appreciate help with mapping values by some settings change or to be able to set select values by myself.

  • allanallan Posts: 63,192Questions: 1Answers: 10,412 Site admin

    Could you show me the JSON that the table is being loaded with (data and options) and also the full Javascript configuration for the DataTable and Editor please.

    Allan

  • pekorpitpekorpit Posts: 7Questions: 3Answers: 0

    Hello Allan, I sent you details about JSON data exchange. It is very basic I think.

    If we find resolution to this smallish but annoying problem, let's document it here so that future generation might benefit from it.

This discussion has been closed.