Bran Smith
Bran Smith

Reputation: 59

How to get data of row from subgrid

I have made a grid thats working fine and subgrids with it. The problem is that I want to send the table name (data of row) in my url to action method but i just have row_id and i dont know how to get data from it. I used the getRowData function but its not working. I dnt know where i am wrong. I've done something like

subGridRowExpanded: function (subgrid_id, row_id) {
    var subgrid_table_id, pager_id;

    subgrid_table_id = subgrid_id + "_t";

    pager_id = "p_" + subgrid_table_id;

    $("#" + subgrid_id).html("
    ");

    var dataFromTheRow = jQuery('#grid').jqGrid('getRowData', row_id);

    $("#" + subgrid_table_id).jqGrid({
        url: "/MyApp/OrdersDetailsSubgridData?tablename=" + dataFromTheRow,
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Column Names'],
        colModel: [
        { name: "COLUMN_NAME", index: "COLUMN_NAME", key: true }

        ],
        rowNum: 20,
        pager: pager_id,
        jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            Id: "0"
        },
        sortorder: "asc",
        viewrecords: true,
        autowidth: true,
        multiselect: false
    });

Upvotes: 0

Views: 3071

Answers (2)

Bran Smith
Bran Smith

Reputation: 59

Extract the name, thus:

var rdata = jQuery("#grid").getRowData(row_id);
var cdata = rdata['tablename'];

and pass it to url, thus:

 url: "/MyApp/OrdersDetailsSubgridData?tablename=" + cdata

Upvotes: 1

Oleg
Oleg

Reputation: 221997

The code which you post have many problems. First of all you don't included what you place under $("#" + subgrid_id).html("...");. The could could be something like

$("#"+subgrid_id).html("<table id='" + subgrid_table_id + "'></table><div id='" +
    pager_id + "'></div>");

The second problem. It's unclear what information from the parent row you need to send to the server as tablename. The name of parameter tablename seems that you want to send some string from some column of the parent string. On the other side getRowData return object with all columns. If you have for example column tablename in the parent grid that you should use

var dataFromTheRow = $(this).jqGrid('getCell', 'tablename', row_id);

instead of using getRowData. If you do need to send content of all columns from the row of the parent grid, then you should first convert the object to the string, using JSON.stringify(dataFromTheRow) for example, and the string can be used as the value of the parameter in the subgrid. You have to decode the JSON information on the server side to be able to process the information.

The last remark. I recommend you to review option of subgrids which you use. For example jsonReader seems to me wrong. I can't suggest correct one because I don't know the format of data which you returns. You should consider to add idPrefix in the subgrid. It's really very important. See the answer for more details.

Upvotes: 0

Related Questions