Search code examples
jqueryjqgrid

How to get the value of all cells in a jqGrid selected row


With the underlying code I get the value of a single cell and do a search, I get all the cell values I want and do a search

I do not want a single cell value I want all the values in the column.

Is there anybody who can help me with this?

        ondblClickRow: function(rowid,iRow,iCol,e){
        var grid=$('#grid');
        var cm = $("#grid").jqGrid("getGridParam", "colModel");
        var colName = cm[iCol]["name"];
        var cellvalue = $("#grid").jqGrid("getCell", rowid, iCol);
        $('#gs_' + colName).val(cellvalue);
        grid[0].triggerToolbar();
        },

Solution

  • It is not clear what you actually want to get - the values of the selected row (as described in the short question) or the values of certain column (as described in the body of your question).

    Anyway it is a good idea to look into the documentation method list of jqGrid. In case of Guriddo jqGrid the documentation is here

    To get the row values use getRowData method

    var rowvalues = $("#grid").jqGrid("getRowData", rowid);
    

    To get the column values use getCol method

    var colName = cm[iCol]["name"];
    var colvalues = $("#grid").jqGrid("getCol", colName);
    

    For detailed description of parameters look at the documentation link provided

    EDIT: In your case to do what you want the code for double click row can look like this:

      ondblClickRow: function(rowid, iRow, iCol, e) {
        var cm = $(this).jqGrid("getGridParam", "colModel");
        var cmvalues = $(this).jqGrid("getRowData", rowid);
        $.each(cm, function(i,n){
            if(!n.hidden) {
                $('#gs_'+n.name).val( cmvalues[n.name])
            }
        });
        this.triggerToolbar();
      },
    

    In order search to work correct the date field should contain equal option for searching - i.e. :

    {
        name: 'invdate',
        width: 90,
        sorttype: "date",
        formatter: 'date',
        formatoptions: {
          newformat: 'm/d/Y',
          srcformat: 'Y-m-d'
        },
        searchoptions : { sopt['eq'] }
      }