====== Importing and exporting ====== There are times when it is useful to be able to import or export the entire grid configuration to another file format: - Grids constructed on the server can be reconstructed after sorting or paging, so a different configuration can be quickly used as required - Grids can be constructed visually on the server and then loaded from an xml string - Grid configuration can even be stored in the database as xml and then loaded as required. It is important to note that jqGrid can load the configuration and data at once. ===== Installation ===== In order to use this module you should mark the Import/Export and XML/JSON utils when you download the grid. For more information refer to [[Download]].\\ For Developers - these are JsonXml.js and grid.import.js files in the src directory. ===== Methods ===== ==== Exporting ==== To export the current grid configuration we use jqGridExport called this way: jQuery("#grid_id").jqGrid('jqGridExport', options); Where * grid_id is the id of the already constructed grid * options is array of pair name:value to set different configuration listed bellow It is good idea first to play with this method before using jqGridImport method. ^Option^Type^Description^Default^ |exptype|string|Determines the type of the export. Two possible values are accepted - xmlstring - the grid configuration is exported as xml string and jsonstring - the configuration is exported as jsonstring|xmlstring| |root|string|This element set the name of the root element when we export the data - i.e. the grid configuration is enclosed in this element. For xmlstring the exported data can look like this \\ jqgrid_configuration \\ . For json string we have \\ {rootelement:{grid_configuration}}|grid| |ident|string|Tab or indent string for pretty output formatting|\t| Since some columns in the grid are created dynamically (row numbers, subgrids and etc) the export method intelligently removes all the not needed data and make the string configuration ready for use in jqGridImport When using these methods the pager parameter in grid options should not be set as : \\ pager: jQuery("#mypager")\\ but as \\ pager : "#mypager" \\ or \\ pager : "mypager" \\ otherwise the import or export will not work. When we make the export we export only the grid configuration and the related events. We do not export the navigator. In order to do this you should manually construct the navigator in the jqGridImport using the importComplete event - see below ==== Importing ==== This method 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. This is done with jqGirdImport jQuery("#grid_id").jqGrid('jqGridImport', options); Where * grid_id is the id of the table element where the grid should be constructed * options is array of pair name:value to set different configuration listed bellow ^Option^Type^Description^Default^ |imptype|string|Determines the type of import Can be one of the following values xml, json, xmlstring, jsonstring|xml| |impstring|string|in case of xmlstring or jsonstring this should be set| | |impurl|string|valid url to the configuration when xml or json. The data is obtained via ajax request| | |mtype|string|Determines the type of request. Can be GET or POST|GET| |impData|object|additional data that can be passed to the url in pair name:value|empty object {}| |xmlGrid|object|describes from where to read the xml configuration and from where the data if any. The option config describes the configuration tag. The option data describes the data tag|config : "roots>grid",\\ data: "roots>rows"| |jsonGrid|object|describes from where to read the json configuration and from where the data if any. The option config describes the configuration tag. The option data describes the data tag| config : "grid",\\ data: "data"| |ajaxOptions|object|Additional options which can be passed to the ajax request |empty object {}| ==== Events ==== There is only one event which can be called in jqGridImport. ^Event^Description^ |importComplete|This event is called after the successfully import and when the grid is constructed. To this event we pas the request from server. Use this event to set additional parameters in the grid or to construct the navigator|