DHTMLX Docs & Samples Explorer

Data scheme

Data scheme allows to set a default scheme for data records of dhtmlXDataStore. So, in cases when you add an empty record to dhtmlXDataStore (data.add({})), the record will be populated with the values set by the scheme.

myDataStore.data.scheme({
	name:"Unknown",
        gender:"male",
        age:25,
        department: "Unknown"
});
myDataStore.add({});//will add { name:"Unknown", gender:"male", age:25, department:"Unknown"} record

Also, there are 2 special keys you can use in a scheme:

  • $init - called during initial object creation

    Let's assume, you want to populate combo with data from some column of db (e.g. column 'name' with the names of departments). To make combo recognize the names of departments as options, combo should get data as sets of 'text' and 'value' parameters. In this situation the $init key comes in useful:

    myDataStore.data.scheme({
      $init:function(obj){
          obj.value = obj.name;// 'name' is the name of the column from the db
          obj.text = obj.name;
      }
    }); 
  • $update - called each time after data changing

    myDataStore.data.scheme({
      $update:function(obj){ 
            obj.text = obj.name + " " + obj.number;
      }
    });