Serialization methods allows getting the grid in XML representation (XML string). Various levels of serializations define the number of grid parameters reflected in the resulting XML:
grid.setSerializationLevel(userData, selectedAttr, config, changedAttr, onlyChanged, asCDATA); grid.setSerializableColumns(list); grid.enableMathSerialization(status); var myXmlStr = grid.serialize();
The methods used in the snippet above are as follows:
Tags used for rows and cells during the serialization can be defined as:
grid.xml.s_row="myrowtag"; grid.xml.s_cell="mycelltag";
The grid uses some predefined set of attributes that will be included in the serialization. But if the user applies some custom attributes, he can force their including in the serialization.
grid.setRowAttribute(id,"custom1","data"); //... grid.xml.row_attrs.push("custom1"); // will include custom1 in the serialization grid.cells(i,j).setAttribute("custom2","data"); //... grid.xml.cell_attrs.push("custom2"); // will include custom2 in the serialization
Serialization to CSV became possible since v1.2:
grid.csv.cell="\t"; // change CSV delimiter var csvNew = grid.serializeToCSV(); // serialize to CSV with the current active delimiter grid.parse(csvNew,"csv"); // load grid from a CSV string // the following code is still possible to use: grid.setCSVDelimiter("\t"); // change CSV csv delimiter var csvNew = grid.serializeToCSV(); // serialize to CSV with the current active delimiter grid.loadCSVString(csvNew);//load grid from a CSV string </script>
The following method is responsible for the mode in which id for rows loaded from CSV is autogenerated:
grid.enableCSVAutoID(true|false);
There is a method that is responsible for including serialized grid as a part of form submitting:
grid.submitSerialization(true|false);
The user should not forget to include dhtmlxgrid_form.js file into the page.