jqgrid addrowdata问题 [英] jqgrid addrowdata problem

查看:187
本文介绍了jqgrid addrowdata问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jqgrid中添加新的空行时遇到问题.

I have a problem with adding a new empty row in a jqgrid.

我的同事是:

colModel: [{ name: 'recid', index: 'testid', hidden: true, editable: true, editrules: { edithidden: true} },
           { name: 'JobTask.Id', index: 'JobTask.Id', hidden: true },
           { name: 'InvolvedParty.Id', index: 'InvolvedParty.Id', hidden: true, editable: true, editrules: { edithidden: true} },
           { name: 'InvolvedParty.Lastname', index: 'InvolvedParty.Lastname', width: 100, align: 'left', editable: true},
           { name: 'deletefield', width: 100, sortable: false, title: false, align: 'center', label: ' '}],

我用来插入行的代码是:

The code I use to insert the row is:

var rowid = jQuery.Guid.New();
var newRowData = [{ "recid": rowid, "JobTask.Id": "@(Model.id)", "InvolvedParty.Id": "", "InvolvedParty.Lastname": "", "deletefield": ""}];
$("#grid_id").addRowData(rowid, newRowData);

然后我输入一些数据并用

then I enter some data and save the row with

jQuery('#grid_id').saveRow(rowid);

一切正常.现在,当我再次按插入时,我得到一个空白 仅包含一个单元格的行,该单元格甚至不可编辑.我新插入的行 应该有两个字段 lastname deletefield ,其中包含两个按钮(删除,保存).

everything works fine. Now when I press the insert again, I get an empty row with just one cell, which is not even editable. My newly inserted row should had two fields lastname and the deletefield which contains two buttons (delete, save).

任何想法为什么会发生这种情况?

Any ideas why is this happening?

推荐答案

尝试代替

var newRowData = [{ "recid": rowid, "JobTask.Id": "@(Model.id)", "InvolvedParty.Id": "", "InvolvedParty.Lastname": "", "deletefield": ""}];

正在做:

var newRowData = { "recid": rowid, "JobTask.Id": "@(Model.id)", "InvolvedParty.Id": "", "InvolvedParty.Lastname": "", "deletefield": ""};

  • 如果这行不通,请确保添加的行确保具有不同的ID

    • if this won't work , make sure that added rows for sure have different ids

      您还可以通过trigger(reloadGrid)

      希望这对我没有更多想法了

      hope that will help i have no more ideas

      好的,我现在出了什么问题

      ok i now what was wrong

      来自jqgrid Wiki:

      from jqgrid wiki :

      ...此方法可以插入多个 行一次.在这种情况下,数据 参数应定义为 [{name1:value1,name2:value2…}, {name1:value1,name2:value2…}]和 第一个选项rowid应该包含 来自数据对象的名称,应该 充当该行的ID.它不是 必要的是rowid的名称 在这种情况下,应该是 colModel.

      ... This method can insert multiple rows at once. In this case the data parameter should be array defined as [{name1:value1,name2: value2…}, {name1:value1,name2: value2…} ] and the first option rowid should contain the name from data object which should act as id of the row. It is not necessary that the name of the rowid in this case should be a part from colModel.

      表示您应该也可以使用[]的

      :

      that meens you should be able also to use [] like that :

      var newRowData = [{ "recid": rowid, "JobTask.Id": "@(Model.id)", "InvolvedParty.Id": "", "InvolvedParty.Lastname": "", "deletefield": ""}];
      
      $("#grid_id").addRowData("recid", newRowData);
      

      这篇关于jqgrid addrowdata问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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