TableDnD icon indicating copy to clipboard operation
TableDnD copied to clipboard

Problem with tableDnDSerialize()

Open MTester2 opened this issue 7 years ago • 6 comments

I can drag/drop ok, but the serializing is not working. I've tried this with 1.0.3 and with 0.9.1, same problem.

I've created a very basic Fiddle (using 0.9.1) that shows the problem (use F12 to view console). It happens when you drag a row (though it works), or when you click the Serialize button.

I've posted the errors here as well for reference...this is with 0.9.1.

This is the dragging/dropping one: Uncaught TypeError: Cannot read property 'tableDnDConfig' of null at Object.processMouseup (jquery.tablednd.js:502) at HTMLDocument.mouseup (jquery.tablednd.js:552) at HTMLDocument.dispatch (jquery.js:5183) at HTMLDocument.elemData.handle (jquery.js:4991) processMouseup @ jquery.tablednd.js:502 mouseup @ jquery.tablednd.js:552 dispatch @ jquery.js:5183 elemData.handle @ jquery.js:4991

This is the clicking the button to get the serialized data: ncaught TypeError: Cannot read property 'tableDnDConfig' of null at Object.tableData (jquery.tablednd.js:590) at Object.serialize (jquery.tablednd.js:566) at jQuery.fn.init.proxy [as tableDnDSerialize] (jquery.js:10268) at HTMLButtonElement.onclick ((index):392) tableData @ jquery.tablednd.js:590 serialize @ jquery.tablednd.js:566 proxy @ jquery.js:10268 onclick @ (index):392 Any help would be appreciated, or I need to find another plugin. If this is not an error, just me doing something wrong, it would be great if you could point that out too. Thanks.

MTester2 avatar Aug 03 '18 21:08 MTester2

Using the 1.0.3 version I have local, I saw on line 518, where it starts: tableData: function (table) { that var config = table.tableDnDConfig, etc is being done, before the checks to see if table is valid. I moved those checks (lines 530 to 535) (on my local copy) above the declaration for config, and now I get the error:

Not a valid table.

coming from line 533 (on the unmodified js file). This would be: if (!table || !table.rows || !table.rows.length) return {error: { code: 500, message: "Not a valid table."}};

Note: On 0.9.1, these are lines 589 - 604.

Also, when I tried the fiddler again just now, the first error (dragging/dropping) I reported in my original post went away... but the second one to get the serialized data is still happening.

MTester2 avatar Aug 04 '18 07:08 MTester2

Hi, this is very strange. I can confirm that I can reproduce your error, but I haven't worked out why it's happening yet.

I don't think it's a change in the code. This bit of the code hasn't changed in quite a long time. I think it's to do with the usage, but I'll continue investigating and keep you posted.

isocra avatar Aug 06 '18 17:08 isocra

Here's a work around. You can save the serialised data every time a row is dropped and then fetch it when you click on the button. In your fiddle, just change the javascript to:

$(document).ready(function() {
    // Initialise the table with an onDrop event handler so we can store the data
    $("#table-1").tableDnD({
      onDrop: function (table, row) {
        $(table).data('serialised', $.tableDnD.serialize());
      }
    });
    $("#serialiseButton").click(function() {
      var data = $('#table-1').data('serialised');  // Fetch the stored data (NB doesn't work if no drag yet)
      alert('The serialised data is ' + data);
    });
});

isocra avatar Aug 06 '18 19:08 isocra

Hi, thanks for the response. Yeah, it had me scratching my head, because it should work...

I did end up doing something very similar to your workaround. Only difference was that I just created a variable to store it in each time, then when the use clicks the button, I retrieve that.

I'll keep on eye out to see what you decide the issue was. Thanks!

MTester2 avatar Aug 06 '18 20:08 MTester2

Certainly strange. Could it be to do with a change in modern jQuery?

brendon avatar Aug 06 '18 21:08 brendon

I was having issues with tableDnDSerialize() too. I used tableDnDSerializeAll() instead and the data I was expecting was returned.

JamoCA avatar Sep 01 '20 01:09 JamoCA