dhtmlxgrid:获取网格数据的xml字符串 [英] dhtmlxgrid: getting an xml string of grid data

查看:427
本文介绍了dhtmlxgrid:获取网格数据的xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dhtmlxgrid文档说我应该能够通过序列化功能获取带有网格数据的字符串。



有什么方法可以从dhtmlx网格中获取当前数据,以便能够从中创建自己的xml文件?

解决方案

以下是关于dhtmlxgrid的解答,对于任何正在寻找具有灵活API的网格和没有针对数据库进行硬编码的网格的人来说,dhtmlxgrid都可能有用。我需要一些东西来支持XML数据存储。我查看了几个网格,这是一个最直接的API,同时具有向网格添加数据和从网格中提取数据的灵活性。此外,它具有所有预期的功能,无需额外的编码:隐藏列,排序,拖放操作......以及许多其他未测试的功能:过滤,上下文菜单。它似乎没有编辑细节弹出窗口,但可以很容易地用提供的方法添加。



dhtmlxgrid中的序列化方法确实会返回一个带有当前网格内容。方法.serialize()返回XML字符串(带有dhtmlxgrid特定结构),.serializeToCSV()返回一个csv字符串。有指定分隔符的选项。



dhtmlxgrid确实有一个链接到数据库的数据处理器。但它也有手动处理数据的方法,特别是当您有文本文件或XML存储时。这些是dhtmlxgrid中的方法,可用于将数据添加到网格中并从网格中提取数据:

将数据添加到网格

  grid.loadXML(url)//从远程文件加载数据
grid.loadXMLString(string); //从JS字符串加载数据
grid.parseXML(object); //从XML对象(xmlhttprequest或XML岛)加载数据

grid.loadCSV(url)//从远程文件加载数据;
grid.loadCSVString(string); //从JS字符串加载数据

grid.load(url)//从远程文件加载数据,默认情况下为XML;
grid.load(url,csv)// CSV格式相同;
grid.load(url,json)// JSON格式相同;
grid.load(url,jsarray)// JSArray格式相同。

grid.parse(object)//从字符串|对象加载数据,默认情况下为XML;
grid.parse(url,csv)// CSV格式相同;
grid.parse(url,json)// JSON格式相同;
grid.parse(url,jsarray)// JSArray格式相同。

◦url - 外部文件的网址;

调用 - 加载后的回调函数;可选参数,可以省略;

type - 数据类型(xml,csv,json,jsarray);可选参数; xml默认情况下。



对于这些方法,文档可以在 dhtmlx网格加载数据文档



从网格中提取数据

  var xmlstring = grid.serialize(); //将网格序列化为xml格式
var csvstring = grid.serializeToCSV(); //将网格序列化为CSV格式
grid.setSerializableColumns(...)//将标志设置为true以便列序列化

这些方法的文档可以在 dhtmlxgrid序列化文档



API

在这里找到了 。您会发现所有网格功能的TOC都包含指向API的链接(按字母顺序排列或分类)。

样本



样本可以在这里。您可能需要查看几个样本才能找到涵盖您具体情况的样本。通常他们会有一些有用的东西。 行和列操作中的示例说明了如何使用一个网格的API。

由于大量研究发现了具有这些功能的东西,我想我会在这里提供这些信息。


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?

解决方案

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.

这篇关于dhtmlxgrid:获取网格数据的xml字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆