jqxGrid API source

source 源对象表示一组键/值对。

The source object represents a set of key/value pairs.
url: A string containing the URL to which the request is sent.
data: Data to be sent to the server.
localdata: data array or data string pointing to a local data source.
datatype: the data's type. Possible values: 'xml', 'json', 'jsonp', 'tsv', 'csv', 'local', 'array', 'observablearray'.
type: The type of request to make ("POST" or "GET"), default is "GET".
id: A string containing the Id data field.
root: A string describing where the data begins and all other loops begin from this element.
record: A string describing the information for a particular record.
datafields: An array describing the fields in a particular record. Each datafield must define the following members:
name - A string containing the data field's name.
type(optional) - A string containing the data field's type. Possible values: 'string', 'date', 'number', 'bool'.
format(optional) - Sets the data formatting. By setting the format, the jqxDataAdapter plug-in will try to format the data before loading it.
Example: { name: 'SubmitDate', type: 'date', format: "yyyy-MM-ddTHH:mm:ss-HH:mm" }
map(optional) - A mapping to the data field.


url:请求地址,即数据来源,例如当datatype类型为xml,即需要url请求到目标文件获取数据

var source = {
    datatype:"xml",
    url="../sampledata/products.xml"
}

data:发送到服务器的数据,目前还没有遇到,补充中...
localdata:本地数据,与url功能相同;
datatype:数据类型,如果用url获取数据,则需要确保datatype正确,用localdata则无要求,类型有 'xml', 'json', 'jsonp', 'tsv', 'csv', 'local', 'array', 'observablearray';
type:请求类型,post、get,默认为get;
id:用处不详???
root:即一条数据被什么元素包裹,

root:"demo"
xml文件

  
     
         3
         32.3800
     
  

record:与root用法相同。
datafields:表格通过什么字段取值,其中name字段为必须,即localdata或者url中数据的字段名,type,可有可无,可能的值:'string','date','number','bool';format,可有可无,管道或者过滤器,仅支持时间;map,可有可无,xml的映射路径;

Example with XML data: 
{ name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName' } 
XML
 
    
      ALFKI
      Alfreds Futterkiste
    
  
*** ***
Example with nested JSON data. 
var data = [{ "empName": "test", "age": "67", "department": { "id": "1234", "name": "Sales" }, "author": "ravi"}];
// prepare the data
var source =
{
    datatype: "json",
    datafields: [
        { name: 'empName' },
        { name: 'age' },
        { name: 'id', map: 'department>id' },
        { name: 'name', map: 'department>name' },
        { name: 'author' }
    ],
    localdata: data
};
var dataAdapter = new $.jqx.dataAdapter(source);

注意事项

当使用source 对象时,需要引入jqxdata.js
requires jqxdata.js
但是,当我们用source生成源数据后,还不能直接被jqxGrid使用,需要通过jqx的内置方法转换之后才能使用

var dataAdapter = new $.jqx.dataAdapter(source);

你可能感兴趣的