Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with tableDnDSerialize() #89

Open
MTester2 opened this issue Aug 3, 2018 · 6 comments
Open

Problem with tableDnDSerialize() #89

MTester2 opened this issue Aug 3, 2018 · 6 comments

Comments

@MTester2
Copy link

MTester2 commented Aug 3, 2018

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
Copy link
Author

MTester2 commented Aug 4, 2018

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.

@isocra
Copy link
Owner

isocra commented Aug 6, 2018

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
Copy link
Owner

isocra commented Aug 6, 2018

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);
    });
});

@MTester2
Copy link
Author

MTester2 commented Aug 6, 2018

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!

@brendon
Copy link
Collaborator

brendon commented Aug 6, 2018

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

@JamoCA
Copy link

JamoCA commented Sep 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants