When you deal with multiple related components on client-side, you can define rules how their data will be linked. So changed value in some component will be reflected in other components.
There are 2 main ways to link data:
In both cases, based on configuration:
Basically, you can load data just once, in single global data store and define rules, how different components will use it.
Functionality described above can be applied to the following components:
barChart.sync(myStore);
mycombo.sync(myStore);
mycombo.bind(mygrid);
mycombo.dataFeed("data/combo.php");//specify here the path to a file which will get change requests mycombo.bind(myview);
myview.sync(myStore);
myview.bind(grid);
myview.dataFeed("data/dataview.php");//specify here the path to a file which will get change requests myview.bind(myform);
myform.bind(myStore);
myform.bind(mygrid);
Beware, for correct running you should specify the same IDs for grid columns and form controls:
myGrid.setColumnIds("col1, col2, col3"); var formData = [ {type: "input", name:"col1"}, {type: "input", name:"col2"}, {type: "input", name:"col3"} ] myform = new dhtmlXForm("box", formData);
myform.dataFeed("data/form.php");//specify here the path to a file which will get change requests myform.bind(mygrid);
myform.bind(mygrid); myform.attachEvent("onButtonClick", function(id){ myform.save() //will push updates back to the master list });
If you have 2 forms bound to a DataStore object, sequential saving their changes can provoke data loss. In this case, use the saveBatch() method to prevent losses and save data simultaneously.
myform1.bind(myStore); myform2.bind(myStore); myStore.saveBatch(function(){ myform1.save(); myform2.save(); });
mygrid.sync(myStore);
mygrid.sync(myStore); mygrid.attachEvent("onRowSelect", function(id){ data.setCursor(id); }); myform.bind(myStore);
mygrid.bind(myCombo, function(data, filter){ return myGrid.cells(data, 2).getValue() == filter.text; }); //or mygrid2.bind(mygrid1, function(data, filter){ filter.name = data.cell1[0]; //the first letter of the selected author }); //or mygrid.bind(tree, function(data,filter){ filter.name = data.text; });
mygrid.dataFeed("data/grid.php"); //specify here the path to a file which will get change requests) and it will help you to load new data from the server (instead of the master component) mygrid.bind(myform, function(master, data){ if (master.Name == "") return true; return mygrid.cells(data, 1).getValue().toLowerCase().indexOf(master.Name)!=-1; }); //each time, when some value in form is changed, //grid will be filtered, based on defined logic
mytree.bind(myview);
mytree.dataFeed("data/tree.php"); mytree.bind(mygrid);
Components which are used as source of bind operation receive few extra events and API commands, which allow you to push data in slave components.
You can use
mygrid.setCursor(item_id)
to force loading of the necessary data in all components, which use the grid as the master control.
and
var id = mygrid.getCursor()
to get the current position of the cursor.