Returning multiple arrays for both tables and editor

Returning multiple arrays for both tables and editor

epoch1epoch1 Posts: 17Questions: 8Answers: 1

Hi,

I know that similar questions have been asked but I'm having a hard time figuring the best way to this.

I'm using Editor and I'm trying to return additional arrays (together with the json used to populate my DT) that I can use to populate multiple select options in the Editor modal window.

var dt = $('#dt').DataTable( {
"ajax": '/getAjax'
(assign json to global? Use global.array1 as select option, global.array2 as select 2 option)
...
});

Could someone give me a straightforward example please.

I can't find a way to assign the additional arrays to a global variable so that I can use them as select options. I thought about using initEdit/initCreate to do another ajax call to get the select options but it would be more efficient if I can do it in one call.

One more question. If I use the select field's update method to replace select options on edit will the corresponding field that is displayed in the datatable row still display as the selected value in the dropdown when modal opens? Hope that makes sense.

Thanks

This question has an accepted answers - jump to answer

Answers

  • epoch1epoch1 Posts: 17Questions: 8Answers: 1

    Just to be a little more thorough this is what I have so far:

    //Global var
    var d;

    function cb(json){
    d = json;
    }

    var dt = $('#dt').DataTable( {
    "ajax": function (data, cb, settings) {
    $.ajax({
    url: '/getJson',
    data: data,
    success:function(data){
    cb(data);
    }
    });
    },
    "columns": [
    ...

    But if I try the following d is undfined:

    editor.on( 'onInitCreate', function ( e, mode, action ) {
    console.log(d);});
    });

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    This Editor example shows an array of items being used for both DataTables and in Editor. It uses a checkbox select in Editor, but if you were to replace type: 'checkbox' with type: 'select', multiple: true, it would work exactly the same way.

    What I'm not really understanding is why you are making your own Ajax call. If you have load data just use data rather than ajax.

    Allan

  • epoch1epoch1 Posts: 17Questions: 8Answers: 1

    Thanks Allan,

    Yes, that all makes sense, it was just me misunderstanding.

This discussion has been closed.