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

m-datatable–on-check: retrieve elements and display on textboxes


  • mhykgyver
    Participant

    Posts: 53
    Member Reply #15054

    Hi,

    I’ve checked the console logs for m-datatable–on-check and I can’t figure out how to extract all the fields in the selected row so I can display it in textboxes. Can you guide me on how to do it? TIA

    Attachments:
    You must be logged in to view attached files.
    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #15097

    Hi 🙂

    Can you try this code?

    var datatable = $(‘.m_datatable’).mDatatable(options).on(‘m-datatable–on-check’, function() {
    // select active rows
    datatable.row(‘.m-datatable__row–active’);
    // check selected nodes
    if (datatable.nodes().length > 0) {
    console.log(datatable.nodes().data(‘obj’));
    }
    });

    Thanks


    mhykgyver
    Participant

    Posts: 53
    Member Reply #15111

    Hi Jai,

     

    thanks for the snippet, I added it to my code and it seems that I’m getting nothing for the row, it’s empty as per screesnhot of the console log:

     

    Attachments:
    You must be logged in to view attached files.
    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #15199

    Hi 🙂

    How about this one?

    datatable.on(‘m-datatable–on-check’, function() {
    // select active rows
    var r = datatable.getSelectedRecords();
    console.log(r);
    });

    Thanks


    mhykgyver
    Participant

    Posts: 53
    Member Reply #15344

    Hi Jai,

    For the code snippet, it works but I still can’t get the fields.  When I try to check the methods for I can see my fields.  Please refer to screenshot.

    Attachments:
    You must be logged in to view attached files.

    mhykgyver
    Participant

    Posts: 53
    Member Reply #15347

    I forgot to add, in the console log I can see the field values in the innerHTML property…

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #15397

    Hi 🙂

    In the “r” var can you get the row data object?

    var r = datatable.getSelectedRecords();
    console.log($(r).data(‘obj’));

    Thanks


    mhykgyver
    Participant

    Posts: 53
    Member Reply #15519

    Hi Jai,

    Thank you so much for the reply.  I can finally see the fields, and I can now place them in my text inputs and as a future reference for anyone who needs the same implementation in their projects, this is how I coded mine:

     .on(“m-datatable–on-check”, function() {

    var _row = _table.getSelectedRecords();

    // console.log($(_row).data(‘obj’));

    // console.log($(_row).data(‘obj’).addressBook_addressNo);

    document.getElementById(‘txtCode’).value = $(_row).data(‘obj’).addressBook_addressNo;

    });

    …Thanks again for the fantastic support… more power to you and your team.

    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #15550

    Hi @mhykgyver

    All the best for your projects.

    Thanks


    parag44
    Participant

    Posts: 42
    Member Reply #19356

    Hi @jai,

    I am not able to retreive data when clicked on any checkbox. I need to extract data amd use it whenever i click on some checkbox.

    I did used  this.datatable.setSelectedRecords().getSelectedRecords() but that throws setSelectedRecords as undefined error(pic-1) maybe i am not using it in rightway. Can you please help how to extract data in my case.

    Attaching my code. Please check.

    Thanks,

    Parag

    Attachments:
    You must be logged in to view attached files.
    Jai
    Jai
    Keymaster

    Posts: 2700
    Support Staff Reply #19387

    Hi 🙂

    Please check the variable this.datatable should be an instance of mDatatable.

    Check by console.log(this.datatable);

    Thanks

You must be logged in to reply to this topic.