This topic contains 11 replies, has 3 voices, and was last updated by Jai Jai 7 months, 1 week ago.

DataTable dynamic columns


  • dr.morz
    Participant

    Posts: 8
    Member Reply #12369

    Hello!

    How can I create columns from AJAX request?

    I have json request with many data. And me want create table with columns from this params.

    Example: {data:[{'param1": "value1"}], columns: [{'title':'Param 1", 'data': 'param1', visible: true}]}

    • This topic was modified 11 months, 1 week ago by  dr.morz.
    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #12446

    Hi 🙂

    Sorry, currently the datatable does not support custom data structure.

    Thanks


    dr.morz
    Participant

    Posts: 8
    Member Reply #12460

    You are planning for implementation this?

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #12482

    Hi 🙂

    Any request from users, we will consider to implement it in the future updates.

    Thanks


    dr.morz
    Participant

    Posts: 8
    Member Reply #13674

    The last update did not add this function to DataTable.

    Very sad 🙁

    Tell me, how can I do this at moment?

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #13715

    Hi 🙂

    We are sorry that we could not make it include it in the last update.

    At the moment, I can suggest you to create another temporary API to call to get a list what columns will have and prepare the columns definition for datatable before the real datatable initialized. How’s about that? Hope it will help for now.

    Thanks


    dr.morz
    Participant

    Posts: 8
    Member Reply #13716
    This reply has been marked as private.
    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #13717

    Hi 🙂

    No need. You can add it to your init code. Here is the flow.

    Let say you want to reuse your existing api, so it will be called twice. First call it on your own for columns definition, and 2nd one will called in datatable for data.

    var response = {data:[{‘param1″: “value1″}], columns: [{‘title’:’Param 1”, ‘data’: ‘param1’, visible: true}]};

    Define your columns inside options.

    var options = {
    ….
    // define columns here
    ….
    };

    Then start to init the datatable with prebuilt options.

    var datatable = $(my_datatable).mDatatable(options);

    This is just a temporary workaround, after the feature released soon, you can just remove it.

    Thanks

    • This reply was modified 9 months, 2 weeks ago by Jai Jai.

    ynet
    Participant

    Posts: 3
    Member Reply #15478

    What if the child datatable is inside a modal that is dynamically called by a column template?  How would you init?

     

    I have a column template returning a modal that has another small datatable inside of it.  I want to init that datatable by ID which is XXXXX_ID_{data.Id}.  I need to call the init after the modal window is present otherwise it of course does not find the second datatable.  Is there a way to call the init once the modal (column template) is present on the page?

     

     

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #15518

    Hi 🙂

    Can you do datatable init after modal initiliazed and shown?

    $(‘#myModal’).on(‘show.bs.modal’, function () {
    // do something…
    })

    Thanks


    ynet
    Participant

    Posts: 3
    Member Reply #15553

    Perfect..  I ended up doing just that!  Thanks for the response!

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #15611

    All the best for your projects. Thanks

You must be logged in to reply to this topic.