p.pradnya
p.pradnya

Reputation: 1079

onSelectRow in a JQGrid

I have gone through the solutions given for not working onSelectRow but they could not worked for me.

I have following code :

$("#myActions_gridTable").jqGrid({
        datatype:'local',
        data: myActionsData,
        cellsubmit: 'clientArray',
        cellEdit: true,
        rowNum: noOfLinesToDisplay,
        pager: $("#myActions_pager"),
        sortname: 'contract_Name',
        viewrecords: true,
        sortorder: 'asc',
        autoWidth:true,
        loadonce: true,
        cmTemplate: { title: false },
        height:'auto',
        scrollrows: true,
        colNames:["id","Status"],
        colModel:[
            {
                name:'id',index:'id', jsonmap:'id', width:1,hidden:true,key:true, editable:true
            },

            {name:'status',index:'status', align:'center', sortable: false,
                editable: true,
                edittype: "select",
                width: 150,
                editoptions: {
                    value: "1:Done;2:Running"
                }

            }
        ],


        onSelectRow : function(id){ 
            console.log('inside onSelectRow');
            if (id && id !== lastsel) {
                $('#myActions_gridTable').restoreRow(lastsel);
                $('#myActions_gridTable').editRow(id, true);
                lastsel = id;
            }

        }
    });

Here OnSelectRow does not get fired, no console.log is printed. Please help.

Upvotes: 0

Views: 16221

Answers (3)

hobbydev
hobbydev

Reputation: 1709

OnSelectrow is not working when cellEdit is true.

You can use onCellSelect instead of OnSelectrow.

Upvotes: 1

Oleg
Oleg

Reputation: 221997

One possible problem could be the usage of edittype: "select" without usage of formatter: "select". In any way the property editoptions: { value: "1:Done;2:Running" } seems me very suspected if you don't use formatter: "select".

How looks the input data for the column "status"? Do you use 1 and 2 or "Done" and "Running"? If you want to hold 1 and 2 values in the data, but you want to display the values as "Done" and "Running" then you should use

formatter: "select", edittype: "select", editoptions: {value: "1:Done;2:Running"}

The demo demonstrates it. It uses

var myActionsData = [
        { id: 10, status: 1 },
        { id: 20, status: 2 }
    ];

as the input.

Alternatively one can use

var myActionsData = [
        { id: 10, status: "Done" },
        { id: 20, status: "Running" }
    ];

but one should use

edittype: "select", editoptions: {value: "Done:Done;Running:Running"}

in the case. No formatter: "select" are required in the last case: see another demo.

Upvotes: 1

Runcorn
Runcorn

Reputation: 5224

You need to define the variable lastsel as

 var lastsel;

In the above code you need to do :

var lastsel;
$("#myActions_gridTable").jqGrid({
..............
..............
..............,
  onSelectRow : function(id){ 
                        console.log('inside onSelectRow');
                        if (id && id !== lastsel) {
                            $('#myActions_gridTable').restoreRow(lastsel);
                            $('#myActions_gridTable').editRow(id, true);
                            lastsel = id;
                        }

                    }

Here is the working JsFiddle Demo

And could get further info here http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events.

Upvotes: 1

Related Questions