Importing/Exporting Grid Configuration

There are times when it is useful to be able to import or export the entire grid configuration to another file format:
  1. Grids constructed on the server can be reconstructed after sorting or paging, so a different configuration can be quickly used as required
  2. Grids can be constructed visually on the server and then loaded from an xml string
  3. Grid configuration can even be stored in the database as xml and then loaded as required

These methods support doing that.


Method Parameters Returns Description
jqGridExport options Exports the the current grid configuration to the desired format
    $("#mygrid").jqGridExport({exptype:"xmlstring"});
will export the current grid configuration as xml string
    $("#grid_id").jqGridExport({exptype:"jsonstring"});
will export the current grid configuration as json string.

It is good idea first to play with this option before using jqGridImport.
jqGridImport options Reads the grid configuration according to the rules in options and constructs the grid. When constructing the grid for first time it is possible to pass data to it again with the configuration.

IMPORTANT NOTE:
When using these methods the pager parameter should not be set as

pager: jQuery("#mypager"),
but as
pager : "#mypager"
or
pager : "mypager"

otherwise the import or export will not work.

Options

Option Values Description Default
imptype xml, json, xmlstring, jsonstring "xml"
impstring in case of xmlstring or jsonstring this should be set ""
impurl valid url to the configuration when xml or json ""
mtype "GET" or "POST" ""
impData {} additional data that can be passed to the url empty array
xmlGrid {} describes from where to read the xml configuration and from where the data if any
    config : "roots>grid",
    data: "roots>rows"
jsonGrid {} describes from where to read the json configuration and from where the data if any
    config : "grid",
    data: "data"


If the data tag is empty, the grid automatically loads the data according to the url and datatype options of the grid.

Example


options :{ imptype : "xml", // xml, json, xmlstring, jsonstring impstring: "", // in case of xmlstring or jsonstring this should be set impurl: "", // valid url to the configuration when xml or json mtype: "GET", // the type "GET" or "POST" impData : {}, // additional data that can be passed to the url xmlGrid :{ // describes from where to read the xml configuration and from where the data if any config : "roots>grid", data: "roots>rows" }, jsonGrid :{ // describes from where to read the json configuration and from where the data if any config : "grid", data: "data" } }

As a further example of what is needed, the distribution package contains two files: json_test.txt and xml_test.xml to show the different (xml and json) configurations.



  Last Updated: 2/15/2009 | © Tony's jqGrid - a jQuery Plugin, 2010