David
David

Reputation: 218837

jqGrid ShowLink Formatter - Custom ID Parameter

Am I just missing something simple here? Without going into custom formatting, I'd just like to use my ID values for the ID parameter in the showlink formatter. Here is an example of my sub-grid:

subGridRowExpanded: function (subgrid_id, row_id) {
    var subgrid_table_id = subgrid_id + '_t';
    $('#' + subgrid_id).html('<table id="' + subgrid_table_id + '" class="scroll" />');
    $('#' + subgrid_table_id).jqGrid({
    datatype: 'local',
    colNames: ['Order Number', 'Request Type', 'Owner', 'Order Status', 'Status Date'],
    colModel: [{
        name: 'orderid',
        index: 'orderid',
        width: 150,
        key: true,
        formatter: 'showlink',
        formatoptions: { baseLinkUrl: 'AOFOrderFacilities.aspx', idName: 'orderid' }
    }, {
        name: 'type',
        index: 'type',
        width: 100
    }, {
        name: 'owner',
        index: 'owner',
        width: 200
    }, {
        name: 'status',
        index: 'status',
        width: 150
    }, {
        name: 'date',
        index: 'date',
        width: 150
    }],
    sortname: 'num',
    sortorder: 'asc',
    height: 'auto'
    });
    // TODO: Make this into an AJAX call.  This is just for demo.
    var mysubdata = [
    { orderid: 'O00001234', type: 'Data', owner: 'Melanie Martin', status: 'Saved', date: '2/4/2011 11:48:18 AM' },
    { orderid: 'O00001235', type: 'Voice', owner: 'Billy Solomon', status: 'Submitted to TC', date: '2/4/2011 12:03:47 PM' }
    ];
    for (var i = 0; i <= mysubdata.length; i++)
    jQuery('#' + subgrid_table_id).jqGrid('addRowData', i + 1, mysubdata[i]);
}

When the links in the first column of the grid are rendered, they correctly display the orderid value as the text of the column (the pre-pended "O" is intentional, and should be passed through the system like that), but the resulting links are:

http://localhost/somestuff/AOFOrderFacilities.aspx?orderid=1
http://localhost/somestuff/AOFOrderFacilities.aspx?orderid=2

And so on, where the ID parameter value is the ordinal index of the grid row rather than the desired value from the data. Is there an easy way to use the value from the data instead?

Upvotes: 2

Views: 5161

Answers (2)

Richard Parkins
Richard Parkins

Reputation: 145

Not sure if you guys have solved this yet BUT I got it to send across the id of my choice by setting the json reader as follows:

jsonReader: { repeatitems: false, id: "[property whose value you want to pass]" },

Rich

Upvotes: 1

Oleg
Oleg

Reputation: 221997

The format option idName of the formatter showlink say only that the name the parameter in the url which you need. The value of the id is always the rowid. In your example you use

var mysubdata = [
    { orderid: 'O00001234', type: 'Data', owner: 'Melanie Martin',
      status: 'Saved', date: '2/4/2011 11:48:18 AM' },
    { orderid: 'O00001235', type: 'Voice', owner: 'Billy Solomon',
      status: 'Submitted to TC', date: '2/4/2011 12:03:47 PM' }
];
for (var i = 0; i <= mysubdata.length; i++)
    jQuery('#' + subgrid_table_id).jqGrid('addRowData', i + 1, mysubdata[i]);

which give as the rowid of the rows the values 1,2, mysubdata.length. The setting key:true for the column orderid will be ignored by the method addRowData. You can verify in Developer Tools or in Firebug which id has <tr> elements of your grid.

I recommend you to modify the above code or just use data:mysubdata as a additional parameter of jqGrid instead of the usage more slow old method addRowData. Because you defined key:true all should work correct. You can also use localReader:{id:'orderid'} as additional jqGrid parameter.

Upvotes: 2

Related Questions