How to bind null value to jqgrid that contains all

2019-08-30 10:45发布

问题:

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);
}

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

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..

Please help on this..

Updated:

Initially the grid contains no rows..

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

grid data

for example:     
  col1  col2  col3  col4

  Item1 Null  null  null
  Item2 Null  Null  Null

similarly like this:

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

Col2 and Col4 are dropdowns

I am loading select options into dropdown by using

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

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

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.

回答1:

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();
}

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.