views:

297

answers:

1

Been googling all this while on how to convert an html table to something pagable and sortable, and I have stumbled across jqGrid jquery plugin. I've learned so far that we have to call tableToGrid() to convert the table (which we pass as a jquery selector string to the method). I've also tried a host of other things, like for e.g:

tableToGrid('#GridView1');

$('#GridView1').jqGrid({
    rowNum: 10,
    pager: '#pager',
    rowList: [10,20,30]
});

But all these do not provide me with the proper result. Is paging possible when we convert an html table to grid?

A: 

You should try with

tableToGrid('#GridView1', {
    rowNum: 10,
    pager: '#pager',
    rowList: [10,20,30]
});

You can also add more jqGrid options as the second parameter of tableToGrid. You can also get reference to the colModel of the jqGrid after conversion with respect of

var cm = myGrid.getGridParam("colModel");

and then modify some parameters of the column model.

UPDATED: for example with the following code you can set some column data as edittype: "select".

for (var i = 0, l=cm.length; i < l; i += 1) {
    var colModelColumn = cm[i];
    // search for the clolumn with the name colModelColumnName.
    // variables colModelColumnName and selectedOptions are defined
    // in another code fragment above this one
    if (colModelColumn.name === colModelColumnName) {
        jQuery.extend(colModelColumn, { edittype: "select",
                                        editoptions: { value: selectedOptions }});
        break;
    }
}
Oleg
How did you get a reference to `myGrid`?
John
@John: `var myGrid=$("#GridView1");` If one uses in the code many time `$('#GridView1')` which need some searching in the DOM of the page I used save the value in a variable and use it everywhere if I need it. By the way one can use `setColProp` method (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods#add_on_grid_methods) to do the same what I wrote in my old answer.
Oleg
Thank you very much!
John