如何从jqgrid中的dataurl获取行ID或参数以创建动态选择列表以编辑行 [英] How to get row id or parameter from dataurl in jqgrid to create a dynamic select list to edit row

查看:262
本文介绍了如何从jqgrid中的dataurl获取行ID或参数以创建动态选择列表以编辑行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET网站,该网站带有一个使用Jqgrid的C#后端.

I have an ASP.NET website with a C# back-end that uses Jqgrid.

我希望用户能够在网格中选择一个项目进行编辑.可以编辑的字段之一将作为下拉选择列表显示给用户,其中仅包含该用户的有效选项.

I want users to be able to select an item in the grid to edit. One of the fields that can be edited will be presented to users as a drop-down selection list with only valid options for that user.

例如,假设我有一个显示人员的网格.如果编辑了"person1",则用户可以从该项目的选择列表中选择蓝色"或红色",但是如果编辑了"person2",则用户只能从菜单项中选择黄色"或绿色".选择列表.

For example, let's say I have a grid displaying persons. If "person1" is edited, the user may be able to choose "blue" or "red" from the selection list for this item, but if "person2" is edited the user may only choose "yellow" or "green" from the selection list.

我想根据选择的人/行来动态填充选择列表.

I want to dynamically populate the selection list based on what person/row is selected.

我在特定字段上设置了editoptions和dataurl,如下所示:

I have editoptions and dataurl set on the specific field as follows:

editoptions: { dataUrl: 'FetchData.aspx' }

但是,我某种程度上需要某种参数传递给FetchData.aspx页面,以便它可以对特定人员进行背景检查,并为特定人员"创建正确的列表.

Yet, I somehow need some kind of parameter to pass to the FetchData.aspx page so that it can do its background-checking on the specific person and create the correct list for the specific "person".

我希望我可以传递rowid或itemname或以下内容来标识所选的特定行/项目:

I was hoping I could pass the rowid or itemname or something as follows to identify the specific row/item that is selected:

editoptions: { dataUrl: 'FetchData.aspx?selecteditem=' + Id }

如何传递参数,以便可以为特定项目创建正确的项目列表?网络上有无数类似的问题,但是我还没有找到最终的答案...

How can I pass a parameter so that I can create the correct list of items for the specific item? There are countless similar questions on the web, but I haven't been able to find a conclusive answer...

推荐答案

我已经通过添加以下onSelectRow函数解决了该问题(请注意,以下代码中的"Id"代表我想作为参数传递的列的名称) .可以是网格中的任何列名称):

I have solved the problem by adding the following onSelectRow function (note that 'Id' in the below code represents the name of a column I want to pass as parameter. It can be any column name in your grid) :

onSelectRow: function (id) {
  var temp = $("#list").getRowData(id)['Id']
  $("#list").setColProp('mySelectListColumnName', { editoptions: { dataUrl:'FetchData.aspx?selecteditem=' + temp });
}

以上内容有助于传递参数.但是,仅此还不够-它允许FetchData.aspx接收参数并相应地自定义html响应,但是它仅从dataUrl获取一次值-因此,当我选择不同的行时不会刷新.

The above helps to pass the parameter. However, this alone is not sufficient - it allows FetchData.aspx to receive a parameter and customize the html response accordingly, but it only fetches the values once from the dataUrl - so it doesn't refresh when I select different rows.

为解决此问题,我还添加了以下语句:

To solve this, I have also added the following statement:

jQuery.extend(jQuery.jgrid.edit, { recreateForm: true });

这确保了每次单击编辑时都将重新创建编辑表单,这是我想要的,因为每行的编辑表单都会略有不同.完美的作品.希望这对外面的人有帮助-那里有很多选择,这是我见过的最简单的选择.而且有效.

This ensures that the edit form will be recreated every time that edit is clicked, which is what I want since the edit form will be slightly different for each row. Works perfectly. Hope this helps someone out there - there is a maze of options out there and this is the simplest I've seen. And it works.

这篇关于如何从jqgrid中的dataurl获取行ID或参数以创建动态选择列表以编辑行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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