Modify column data from bootstrap modal

Modify column data from bootstrap modal

SuperflySuperfly Posts: 2Questions: 0Answers: 0
edited December 2017 in Free community support

Hi !

I have a datatable with an edit button placed in a row with a 'bt-modal' class.
When clicking it, it displays a bootstrap modal window.

I offer an update of the informations in the given TR in a bootstrap window (there's more informations to edit with complex validity controls). So far so good, this is server side, no problem for that.

Now, where I'm stucked, is when I try to update the informations of the row in the datatable after (or before, I can handle form control client-side) the modal is submitted.

In short (ok, I should maybe have started from here, sry) : How do I reference the datatable so that I can manipulate rows/cells data from my modal ?

Below my JS declarations/functions

$(document).ready( function() {
var forSearch = $('#Tmagasins').DataTable( {
        pageLength: 5,
        [other params like kanguage and so on]
}),
        // The modal call function
            $('.bt-modal').on( 'click', function () {
            tr = this.closest( "tr" );
            magid = forSearch.row(tr).id();
            trindex = forSearch.row(tr).index();
                         //this is just for testing and yes, it works
                                     /*trdata = forSearch.row(tr).data();
                         console.log(trdata);*/
                $('.modal-body').load('dsp_magasin.cfm?id='+magid+'&trindex='+trindex);
                    $('#modModal').modal({show:true});
        })
})

P.S : My HTML setup is pretty simple, as the datatable content is populated when page is loaded; let's pretend it's a basic/static HTML one.

Thanks + sorry for my weird English ... hope you'll get what I mean :)

Replies

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    var forSearch = null;
    $(document).ready(function(){
    forSearch = ...
    blah blah blah
    });

    this will give forSeach a global definition

    your use of "this" inside your click function is a dom object, not a jquery object so
    this.closest will not work use $(this).closest instead.

  • SuperflySuperfly Posts: 2Questions: 0Answers: 0
    edited January 2018

    thank you bindrid and sorry for the late answer. I came to this noobish error of mine too.
    I almost forgot : happy new year !

This discussion has been closed.