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

Custom Field Names issue when dataSource is empty and we want to use addNode method to add nodes and thier children #281

Closed
rabbal opened this issue Mar 3, 2018 · 5 comments

Comments

@rabbal
Copy link

@rabbal rabbal commented Mar 3, 2018

Configuration

var tree = $("#listItems").tree({ primaryKey: 'Id', textField: 'Title', childrenField: 'Children', uiLibrary: 'bootstrap', iconsLibrary: 'fontawesome', checkboxes: true, border: true, dataSource: $("#listItems").data("items") || [] });

Add Node

tree.addNode({ Title: 'node1'}); tree.addNode({ Title: 'node1-1' }, tree.getNodeByText('node1'));

Hint

the problem is in this below code
id = data.primaryKey ? response[i][data.primaryKey] : data.autoGenId++;

@atatanasov
Copy link
Owner

@atatanasov atatanasov commented Mar 3, 2018

What is the error message that you get in this case? What line of code?
Could you provide sample data for $("#listItems").data("items") result in order to be able to replicate the isssue.

@rabbal
Copy link
Author

@rabbal rabbal commented Mar 4, 2018

when dataSource is empty and primaryKey set with "Id" , the id will be undefined.

capture-01
capture-02
capture-03
capture-04

@atatanasov
Copy link
Owner

@atatanasov atatanasov commented Mar 7, 2018

I'm not able to replicate your issue. Here is my example where everything works fine. http://gijgo.com/Temp/91b6e5e4-3700-4165-9f2b-d7e0790a1e75.html

Are you using version 1.8.1? 1.8.1 seems to be working fine.

@rabbal
Copy link
Author

@rabbal rabbal commented Mar 7, 2018

Thank you, Yes I'm using version 1.8.1 .
in your example if you add child node to 'node1' with below code:
tree.addNode({Title:"Title"},tree.getNodeByText("node1"))
you get an error like below:
capture

because the data-id attribute of 'node1' has undefined value

capture

so, in line 620 of tree.js file thrown up one exception.
line 620: gj.tree.methods.getById($tree, $parent.parent().data('id'), $tree.data('records')).children.push(newNodeData);

$tree, $parent.parent().data('id') is undefined, so the result of getById Method is undefined and we can not get children of it.

@atatanasov atatanasov closed this in af26324 Mar 8, 2018
@atatanasov
Copy link
Owner

@atatanasov atatanasov commented Mar 8, 2018

We fixed that in the new development version. You can find the new build in the dist folder at github. Thanks for finding this.

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

Successfully merging a pull request may close this issue.

None yet
2 participants