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

Datatables _fnSetObjectDataFn function does not store array types correctly #81

Closed
jimjaeger opened this issue Jul 15, 2016 · 6 comments

Comments

@jimjaeger
Copy link

Fix for _fnSetObjectDataFn required to handle storing of array types correctly.
Already open a forum entry. Also I already fixed it on a local branch. If you give me rights for branch upload I can provide the fix to you.

  • arrayNotation = aLast.match(__reArray);
    +var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
    +var r = val.length > 0 ? val.split(join) : [];
  • data[ aLast.replace(__reArray, '') ] = r;
  • data[ aLast.replace(__reArray, '') ] = val;
@DataTables
Copy link
Collaborator

Thanks. Could you give me a link to the forum thread please? Does it give details on example data showing the issue as it was?

Pull requests can be sent to the master branch here and I'll consider them for inclusion.

Unit tests are something that DataTables is currently lacking for these methods, although they are inbound.

@DataTables
Copy link
Collaborator

I found it here.

If you could please link to a test case showing the issue that would be great.

@jimjaeger
Copy link
Author

Hi,

here is an example of data for testcase:
{"total_rows":104,"offset":0,"rows":[ {"id" : "myid", "doc" : {"tags" : ["tag1"],"_id" : "myid", "_rev" : "3-188272" } }]

sample table config:

var table = $('#dataTables-projectmetadata').DataTable({
responsive : true,
paging : true,
fixedHeader : true,
stateSave : true,
sAjaxDataProp: 'rows',
rowId: 'id',
"ajax": "/api/metadata",
"columns": [
{ "title": "ID", "data": "id" },
{ "title": "Tags", "data": "doc.tags[, ]", "defaultContent": "" }
]
});

After I modify the entry the new value is now {"id" : "myid", "doc" : {"tags" : "tag12","_id" : "myid", "_rev" : "3-188272" } }

from array to string ....

I guess I have to create a branch and send a pull request after my changes, but I have not access rights to create a branch.

@DataTables
Copy link
Collaborator

Thanks! Let me look into it, but in the short term I would recommend using:

{ "title": "Tags", "data": "doc", render: 'tags.[, ]', "defaultContent": "" }

That takes the array setter out of the equation.

@jimjaeger
Copy link
Author

I already fixed it for me and it works for array and non array values. If you give me branch permission I can provide the fix.

@DataTables
Copy link
Collaborator

Thanks - going to close this thread in favour of the PR you opened - #83. I'm just working my way through e-mails and forum stuff from the weekend so it will be a little while before I can respond there, but I'll review it shortly.

Avaruz pushed a commit to Avaruz/DataTablesSrc that referenced this issue Jan 15, 2024
…DataTables.AspNet.Samples.WebApi2.BasicIntegration/Newtonsoft.Json-13.0.1

Bump Newtonsoft.Json from 9.0.1 to 13.0.1 in /samples/DataTables.AspNet.Samples.WebApi2.BasicIntegration
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

1 participant