fixedColumns rowCallback issue

fixedColumns rowCallback issue

ilyakapitanilyakapitan Posts: 8Questions: 3Answers: 0

I don't know if it is exactly connected to FixedColumns, but since it happens only when activating the extension then I guess it does.

I have a rowCallback which looks something like:

rowCallback: function (row, data, index) {
      var _this = this;
      $(row).click(function (e) {
                var target = $(e.target);
                console.log(target);
                ...
                code
                ...
      });
},

It stops working as soon as I activate fixedColumn extension, I have a regular init on 1 column:

fixedColumns:   {
     leftColumns: 1
},

To be exact, the callback does work, but partially. rowCallback will launch, it will give row data etc, but the click event will continue to work only on columns that are not "fixed". I understand that the plugin changes the html markup, adds extra table etc, but I think the rowCallback needs to address that, that is what makes (or would have) it universal (at least I hoped so). I tried to put a global listener to bypass this issue:

$(document).on('click', row, function (e) {
     var target = $(e.target);
     console.log(target);
});

All the columns work in this case, but I get a crazy spam, when I click on a row I get the data of this row as many times as there are rows on the page.

Test case here.

Replies

  • allanallan Posts: 63,876Questions: 1Answers: 10,529 Site admin

    Assigning events in the rowCallback is generally a really bad idea since, unless you remove the events in future calls (which isn't happening in this case) you are going to end up with a major memory leak.

    I would almost always suggest that you use a single delegated event.

    Its a little more interesting when you use FixedColumns since you can't use the table id as a base selector - you have to use the table container - table().container().

    I've updated your example here: https://jsfiddle.net/d5Ld0x7n/11/

    Allan

This discussion has been closed.