-
Notifications
You must be signed in to change notification settings - Fork 319
can i add data dynamically #5
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
Comments
Yes, i am also want to know if you can provide example in which data can be bind using for loop. |
Adding data from a database is not the job of this library. You need to build a backend process, say in PHP, that obtains the data and then generates the JSON structure to be applied on initialisation. Adding data after initial render is not currently a feature of this library. It may be in the near future, but that would be a much slower way to build your tree than to use the initialisation structure. |
i think you misunderstood, let me explain in detail. I am using following code for generating tree : |
Inside Treant class, the config is copied. So if you edit chart_config you would have to destroy that tree completely and create a new instance. |
Please Can you give me example ? |
I am facing issue same as this issue : #23 |
<?php
$arrayData = array(
array(
'name' => 'dlgoodchild',
'type' => 'master',
'location' => 'Zaragoza'
),
array(
'name' => 'jzapata',
'type' => 'poor kid from africa',
'location' => 'africa'
)
...
);
?> // AN EMPTY JAVASCRIPT ARRAY
var childrenArrayObject = []; // INIT FOREACH
<?php foreach ($arrayData as $key => $data): ?> // FOR EACH CYCLE ... CREATE A JAVASCRIPT OBJECT
var tmpChild = {
// We can use the text object to set custom attributes
text: {
name: '<?php echo $data['name']; ?>',
customAttributeType : '<?php echo $data['type']; ?>',
customAttributeLocation : '<?php echo $data['location']; ?>'
},
// IF YOU DON'T USE innerHTML attribute, all text object will be displayed in a <p> tag
innerHTML : '<p>Information that I want to show</p>'
}
// ADD OBJECT TO OUR ARRAY
childrenArrayObject.push(tmpChild); // END FOREACH
<?php endforeach; ?> // SETUP CHART CONFIG
var chart_config = {
chart: {
container: "#idOfContainer",
callback : {
onTreeLoaded: function () {
var $oNodes = $( '.Treant .node' );
$oNodes.on('click', function (oEvent) {
var $oNode = $(this);
var oMeta = $oNode.data('treenode');
// GET ORIGINAL VALUE OF AN ATTRIBUTE
console.log(oMeta.text.customAttributeType );
// SET NEW VALUE TO AN ATTRIBUTE
oMeta.text.customAttributeType = 'The new type value';
// AFTER THIS THE NEW VALUE IS IN DOM
console.log(oMeta.text.customAttributeType );
}
);
}
}
},
nodeStructure: {
innerHTML : '<p>The main node</p>'
children: childrenArrayObject
}
};
new Treant(chart_config, null, $); |
Yes, i am able to create dynamic tree at 1st time. but can not effect tree when i change data. As i know i need to destroy it first but still not able to load tree on second time. |
You need to add new nodes dynamically or only change HTML code in a node? |
i am generating new "chart_config" and then called this : new Treant(chart_config, null, $); |
In the latest version of Treant I've added a public
|
var my_chart = new Treant(chart_config, null, $);
my_chart.destroy()
my_chart = new Treant(THE_NEW_chart_config, null, $); |
I have uploaded my code here: |
@jainishtesting I can't access to this site ( http://jainishj003-001-site1.atempurl.com/Custom/ ) I need an user and password affter press "ADD" link (Submit event). |
i am able to access . Can you try this one ? and if you don't mind can you contact me on [email protected] ? |
Is this feature implemented fully? ie can we add nodes dynamically and render them? |
The addNode method is there and works? are you having issues? Not really sure how to answer this. |
issue is not solved yet. @sunshinecool . And @dlgoodchild - addNode is different thing. i have requested solution for other issue. |
@jainishtesting make a request specific to your issue with code, not an inaccessible link. The OP's question is irrelevant, because this isn't connected to a database, and there is no data binding, that is something that has to be done outside of this library. This library, builds a tree from data that you compose and provide to it. You can dynamically add more nodes using addNode, which could come from a database. Beyond that, it's outside of the scope of this library. |
Similarly, can i remove nodes dynamically? |
Yes, you can. The controller Namespace Controllers
etc.etc. The view file @ModelType IEnumerable(Of Trial31.Models.Table) Index
the js file to construct chart_config var chart_Config = new Array(jModel.length + 1); chart_Config[0] = config; for (k = 0; k < jModel.length; k++) { var check_table = new Array(); for (j = 1; j < chart_Config.length; j++) { |
how can i add data dynamically fromdatabase??
The text was updated successfully, but these errors were encountered: