Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting jqGrid data after the grid has been created

Tags:

jqgrid

The following example code will load a jqGrid (this code works) ...

jQuery(document).ready(function () {
    var gridData = [
                { col1: 'cell11', col2: 'cell12', col3: 'cell13' },
                { col1: 'cell21', col2: 'cell22', col3: 'cell23' }
                ];
    $('#myGrid').jqGrid({
        data: gridData,
        datatype: 'clientSide',
        colNames: ['Col1', 'Col2', 'Col3'],
        colModel: [
                        { name: 'col1' },
                        { name: 'col2' },
                        { name: 'col3' }
                        ]
    })

How would I rewrite the example so the gridData is set after the jqGrid is created? I tried this...

jQuery(document).ready(function () {
    var gridData = [
                { col1: 'cell11', col2: 'cell12', col3: 'cell13' },
                { col1: 'cell21', col2: 'cell22', col3: 'cell23' }
                ];
    $('#myGrid').jqGrid({
        datatype: 'clientSide',
        colNames: ['Col1', 'Col2', 'Col3'],
        colModel: [
                        { name: 'col1' },
                        { name: 'col2' },
                        { name: 'col3' }
                        ]
    })


    $('#myGrid')[0].data = gridData;

However the above code doesn't work. Can someone show me how please?

UPDATE: I also tried this for my last line, but it didn't work either...

    $('#jqgrid-panel-contents').jqGrid('setGridParam', {data: gridData});
like image 893
John Livermore Avatar asked Feb 23 '11 22:02

John Livermore


People also ask

How do I reset Jqgrid?

$(“#mygrid”). GridUnload(); Call this method to unload the grid and it will clear the contents …

What is colModel in Jqgrid?

In a nutshell, colNames defines the names of your jqGrid columns on the page, and colModel specifies options for each column (name in the dataset, width, etc). The documentation has more information: colModel Array which describes the parameters of the columns. This is the most important part of the grid.

What is the use of Jqgrid?

jqGrid is an Ajax-enabled JavaScript control that provides solutions for representing and manipulating tabular data on the web.


1 Answers

Maybe try reloading the grid afterwards?

 $('#jqgrid-panel-contents').jqGrid('setGridParam', {data: gridData}).trigger('reloadGrid');
like image 173
Ewan Heming Avatar answered Oct 03 '22 23:10

Ewan Heming