This is an old revision of the document!


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:

  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.

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.

OptionTypeDescriptionDefault
exptypestringDetermines 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 jsonstringxmlstring
rootstringThis 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
<rootelement>jqgrid_configuration </rootelement>
. For json string we have
{rootelement:{grid_configuration}}
grid
identstringTab 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
OptionTypeDescriptionDefault
imptypestringDetermines the type of import Can be one of the following values xml, json, xmlstring, jsonstringxml
impstringstringin case of xmlstring or jsonstring this should be set
impurlstringvalid url to the configuration when xml or json. The data is obtained via ajax request
mtypestringDetermines the type of request. Can be GET or POSTGET
impDataobjectadditional data that can be passed to the url in pair name:valueempty object {}
xmlGridobjectdescribes 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 tagconfig : “roots>grid”,
data: “roots>rows”
jsonGridobjectdescribes 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”
ajaxOptionsobjectAdditional options which can be passed to the ajax request empty object {}

Events

There is only one event which can be called in jqGridImport.

EventDescription
importCompleteThis 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

Discussion

Ari Maniatis, 2010/01/14 11:52

You cannot import a configuration on an already loaded grid. Instead, unload it first with GridUnload()

Kishor Mali, 2013/02/01 12:30

multiselect property can not work with jqGridImport xmlstring please reply

You could leave a comment if you were logged in.

QR Code
QR Code wiki:import_methods (generated for current page)