0

I have a status column in one of my jqGrid. It holds value 0 or 1. To me 0 means inactive and 1 means active. So i use a formatter to show the Active/Inactive instead of 0/1 in the grid . When I'm going to edit the record I'm getting that the correct value is not pre selected in the selectbox. In edit view the selectbox always shows Active as selected item. But If I show 0/1 in the grid instead of using the formatter then the edit windows shows the correct value in the selectbox selected item. But I need to show Active/Inactive instead of 0/1.

Formatter

formatter: function(cellValue, options,
                        rowObject) {
                        var val="";
                        if(cellValue=='1')
                            val= "Active";
                        else if(cellValue=='0')
                            val='<span class="cellWithoutBackground" style="background-color:#FFF4F4;color:red;">Inactive</span>';
                        else
                            val= '';

                        return val;
ifti24
  • 191
  • 1
  • 5
  • 22

2 Answers2

0

I just couldn't visualize the exact reasoning behind your issue, But hope this solution will help you.

So the basic foundation for making an row editable as select is done using,

name: 'participants',
index: 'participants',
editable: true,
edittype:"select",

And now you need to define the select option values in key-pair form as,

editoptions:{value:"US:USA;CND:CANADA;FR:FRANCE;LUX:LUXEMBORG"}
//here US is the value of the select box and USA is the label displayed

And in the data you are sending to jqGrid you need to send the value as "US" not "USA" as depicted below,

var localdata = [{
            "name": "Birthday",
            "id": 1,
            "date": 1284393600000,
            "description": "John's 20th",
            "participants": "US"},
        {
            "name": "New Year",
            "id": 2,
            "date": 1294329600000,
            "description": "2011 New Year",
            "participants": "CND"},
        {
            "name": "Christmas",
            "id": 3,
            "date": 1324742400000,
            "description": "Once per year",
            "participants": "LUX"}
        ];

Thus the wrong value for your select value could be the issue you are facing.

Here is the demo for INLINE EDIT JQGRID & NORMAL EDIT

Hope this help your cause.

Regards

Runcorn
  • 5,144
  • 5
  • 34
  • 52
  • And sorry for using different example. – Runcorn Oct 13 '14 at 08:36
  • Hi, Sorry for my late reply. And yes your Normal Edit is that what I'm doing it now. Check the 2nd row of your grid . and check the Participants value. It is - "CND" . But I want that it should show CANADA instead of CND. Imy case the vlaues are 0:Inactive and 1:Inactive. That means in my grid it showing the vlaue 0 or 1 instead of Active/Inactive. And for this reason I have used a formatter for my status column. This formatter works well but when I'm going to edit window then the correct value not selected. Thats the problem. Check my question edit section for the formatter I'm using. – ifti24 Oct 14 '14 at 09:00
0

I would recommend you to use formatter: "select" (see the documentation here) with optional cellattr to set the color of the cell additionally which changes color/background of the cell with "Inactive". See the answer and this one for more examples about the usage of cellattr.

If you would need to highlight the whole row instead of one cell you can use rowattr instead of cellattr (see here).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798