dhtmlxgrid: getting an xml string of grid data

六眼飞鱼酱① 提交于 2019-12-25 05:32:25

问题


The dhtmlxgrid documentation is saying that I should be able to get a string with the grid data with the serialize feature.

Is there any way to get the current data out of the dhtmlx grid to be able to create my own xml file from it?


回答1:


Here are answers about the dhtmlxgrid that might be useful to anyone looking for a grid with a flexible API and one that isn't hardcoded for databases. I needed something to support XML data storage. I looked at several grids and this one was the one with the most straightforward API while having the flexibility for adding data to the grid and for extracting data from the grid. Also, it has all the expected functionality without additional coding: hidden columns, sorting, drag-and-drop..., and many others that I haven't tested: filtering, context menu. It doesn't seem to have an edit details popup but this can easily be added with the provided methods.

The serialize methods in dhtmlxgrid do return a text string with the current grid contents. The method .serialize() returns and XML string (with the dhtmlxgrid specific structure) and the .serializeToCSV() returns a csv string. There are options for specifying delimiters.

The dhtmlxgrid does have a data processor for linking to databases. But it also has methods for manually working with the data, particularly if you have a text file or XML storage. These are methods in the dhtmlxgrid which are useful for adding data into the grid and for extract data from the grid:

Adding data to the grid

    grid.loadXML(url)              // load data from a remote file
    grid.loadXMLString(string);    // load data from a JS string
    grid.parseXML(object);         // load data from an XML object (xmlhttprequest or XML island)

    grid.loadCSV(url)              // load data from a remote file;
    grid.loadCSVString(string);    // load data from a JS string

    grid.load(url)                 // load data from a remote file, XML is expected by default;
    grid.load(url,"csv")           // the same for CSV format;
    grid.load(url,"json")          // the same for JSON format;
    grid.load(url,"jsarray")       // the same for JSArray format.

    grid.parse(object)             // load data from a string|object, XML is expected by default;
    grid.parse(url,"csv")          // the same for CSV format;
    grid.parse(url,"json")         // the same for JSON format;
    grid.parse(url,"jsarray")      // the same for JSArray format. 

◦ url - url to the external file;

◦ call - callback function after loading; optional parameter, can be omitted;

◦ type - type of data (xml,csv,json,jsarray); optional parameter; xml by default.

For these methods the documentation can be found at dhtmlx grid load data documentation.

Extracting data from the grid

    var xmlstring = grid.serialize();      //serialize grid to xml format 
    var csvstring = grid.serializeToCSV(); //serialize grid to CSV format
    grid.setSerializableColumns(...)       //set flag to true for columns to serialize

The documentation for these methods can be found at dhtmlxgrid serialize documentation .

API

The grid documentation can be found here. You will find there a TOC of all the grid features with links to the API (listed alphabetically or categorized).

Samples

The samples can be found here. You might have to look through a few samples to find the one that covers your specific situation. Usually they will have something useful. A sample on row and column manipulation illustrates the use of the API for a grid.

Since a lot of research went into finding something with that set of functionality, I thought I'd make that information available here.



来源:https://stackoverflow.com/questions/8231076/dhtmlxgrid-getting-an-xml-string-of-grid-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!