0

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
    });
Bran Smith
  • 59
  • 1
  • 2
  • 10

2 Answers2

1

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
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Bran Smith
  • 59
  • 1
  • 2
  • 10
0

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hey Oleg ! Thanks for your help. yeah about the first mistake, I added it before but just missed while copying. Moreover I have added var dataFromTheRow = $(this).jqGrid('getRowData', 'tablename', row_id); in the code but its just sending the null value to the action method. Can you tell me the reason? whereas tablename is the only column in my parent grid – Bran Smith Aug 27 '15 at 10:20
  • @BranSmith: You are welcome! Even if you have only one column in the parent grid the value returned by `getRowData` is **object**. For example if you would have the text "TestTable" in the `tablename` column of the parent row then `dataFromTheRow` will be *object* `{ tablename: "TestTable" }` in your old code. The usage of `$(this).jqGrid('getRowData', 'tablename', row_id)` instead will return the required *string* `"TestTable"`. Do you tried the changes? – Oleg Aug 27 '15 at 10:35
  • @BranSmith: Sorry, I could see now the typing error in my text. One should use `getCell` of cause instead of `getRowData`. I fixed the text of my answer. – Oleg Aug 27 '15 at 11:13