从数组本地加载的Jqgrid数据类型 [英] Jqgrid datatype local loading from array

查看:76
本文介绍了从数组本地加载的Jqgrid数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我有关从本地js var问题刷新下划线数据后如何重新应用工具栏过滤器的问题期间,

During my question about how to re-apply the toolbar filter after the underline data is refreshed from a local js var question asked here, Oleg has provided me an solution: 1 use the combination of datatype:"local" and data:localvar.

现在,我面临一个不同的问题,一周后我无法解决.

Now I am facing a different problem which after a week I was not able to solve.

根据Jqgrid Wiki,在使用本地数据源时,默认的localreader类似于

According to the Jqgrid wiki when using local datasource the default localreader looks like

The initial configuration of the localReader is the same as those from jsonReader

localReader = {
   root: "rows",
   page: "page",
   total: "total",
   records: "records",
   repeatitems: false,
   cell: "cell",
   id: "id",
   userdata: "userdata",
   subgrid: {root:"rows", repeatitems: true, cell:"cell"}
}

我发现情况并非如此.因为在每个使用dataype:"local"可以找到的示例中,它总是使用直接的js数组代替js对象,如下所示:

I found this is not the case. Because in every examples that i can find using dataype:"local", it always uses a straight js array in stead of an js object, looking like this:

var mydata = [       
{id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},   
   {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"}, 
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}];

我尝试使用默认的localReader(将repeatitems设置为true)来处理

I have tried using the default localReader (with repeatitems set to true) to process

var locObj = {"rows":[
       {"id":0,"cell":["val1","val2","val3"]},
       {"id":1,"cell":["val1","val2","val3"]}
        ],
  "page":"1",
  "total":"1",
  "records":"2"
}

与 数据类型:本地", 数据:locObj

with datatype:"local", data:locObj

这将不起作用,因为它不会通过addlocaldata函数中的数组检查.如果我将选项更改为 数据类型:本地", 数据:locObj.rows

this will not work, because it wont pass the array check in the addlocaldata function. if I change the option to be datatype:"local", data:locObj.rows

我有一个正确的行数网格,但是每个单元格都有一个空值.我认为这是因为addlocaldata函数无法处理格式为locObj.rows的数组.

I got a grid with correct number of rows but each cell has an empty value. I think that is becasue the addlocaldata function can not handle an array formatted like locObj.rows.

有没有一种方法可以使用自定义的localreader来实际处理数据类型为"local"的json对象(或字符串)(而不必在客户端重新创建数组)?

is there a way to actually process a json object (or string) with the datatype:"local" using the customised localreader (in stead of having to re-create an array on the client side)?

非常感谢您的帮助.

Casbby

推荐答案

您需要做的只是使用

data: locObj.rows,
localReader: {repeatitems: true}

请参见相应的演示.

这篇关于从数组本地加载的Jqgrid数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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