如何将空值绑定到包含可编辑格式的所有行的jqgrid [英] How to bind null value to jqgrid that contains all rows in Editable format

查看:228
本文介绍了如何将空值绑定到包含可编辑格式的所有行的jqgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net应用程序中使用jqgrid.我在jqgrid的LoadComplete触发器中以可编辑的格式制作所有网格行,如下所示:

I am using jqgrid in my asp.net application. I am making all the grid rows in editable fomat in the LoadComplete trigger of the jqgrid as follows:

 ids = $("#grid").jqGrid('getDataIDs');
                    var l = ids.length;
                    for (var i = 0; i <= l; i++) {
                        $("#grid").jqGrid('editRow', ids[i], true);
}

在两列中,我有一个下拉列表.在此,基于外部下拉列表的更改,一些行被添加到jqgrid中.

In two of the columns , i have dropdown lists . Here, the based on the external dropdown change, some rows get addded to the jqgrid.

添加后,它们最初包含Null值.

When added, they contain the Null values initially.

因此,为了在网格中显示空值.我要添加一个列表项以显示它们.

So, inorder to show null values in grid. I am adding an list item , to display them.

问题出在这里,我不应该允许用户再次选择空值.

The problem is here , i should not allow users to again select null values.

因此,在进行选择之前,仅需要一次在下拉列表中使用该选项.

So, i need that option in the dropdown list only once that is before a selection is made.

稍后,它应该不可见或不可选择.

later, it should not be visible or selectable..

请对此提供帮助.

已更新:

最初,网格不包含任何行.

Initially the grid contains no rows..

在下拉菜单更改中,将刷新网格并根据下拉菜单选择添加新行.

On the dropdown change , the grid gets refreshed and new rows are added based on dropdown selection.

网格数据

for example:     
  col1  col2  col3  col4

  Item1 Null  null  null
  Item2 Null  Null  Null

类似这样:

此处,Col1是不可编辑的,其余的都是可编辑的.

Here, Col1 is not editable rest of them are editable.

Col2和Col4是下拉列表

Col2 and Col4 are dropdowns

我正在通过使用将选择选项加载到下拉列表中

I am loading select options into dropdown by using

 editoptions: {
                    value: { " ": " ", "option1": "option1", "option2": "option2", "option2": "option2", "option3": "option3" },

在这里,我的问题是..用户不应该选择该null选项.

Here, my problem is that .. the user should not be able to select that null option .

我已将其包含在初始数据绑定中. 如果我不包括该空选项(") 则下拉列表显示为默认选项1,但用户尚未选择任何选项.

I have included it for the intial data binding. IF i am not including that null option("") then the dropdowns are showing with option 1 as default but the user has not yet selected any option.

推荐答案

我不确定我是否知道可以解决您的问题.如果只需要从下拉列表中删除null""条目,则可以使用dataInit(

I am not sure that I understand correct your problem. If you just need to remove null or "" entry from drop-down you can do this by using dataInit (the property of editoptions). The corresponding code could be about the following

dataInit: function (elem) {
    $(elem).find("option[value=\"\"]").remove();
}

也许其他实现可能对您更好.例如,如果当前选择的选项是"",则可以取消选择任何选项.有关详细信息,请参见答案.无论如何,我认为您应该使用dataInit进行一些更正.

Probably other implementation could be better for you. For example you can unselect any option if the current selected option is "". See the answer for details. In any way I think that you should use dataInit to makes some corrections.

这篇关于如何将空值绑定到包含可编辑格式的所有行的jqgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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