Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically Defining a jqGrid
    primarykey
    data
    text
    <p>I am trying to make an ad-hoc query page for our ASP.NET MVC 2 application. This page is secured and used strictly for technical administrative access on our intranet. We want the ability to query a handful of tables and I don't want to have to have a page/grid per query. I have an MVC controller that returns a JSON result that includes the following values (I got these from client-side javascript alerts, so I know this is what these values look like "at the grid"):</p> <p>colNames contains:</p> <pre><code>['AccountID','ClientID'] </code></pre> <p>colModel contains: </p> <pre><code>[{editable:false,index:'AccountID',jsonmap:'AccountID',key:false,name:'AccountID',resizable:true,search:false,sortable:true,width:300}, {editable:false,index:'ClientID',jsonmap:'ClientID',key:false,name:'ClientID',resizable:true,search:false,sortable:true,width:300}] </code></pre> <p>colData contains:</p> <pre><code>{total:1,page:1,records:1,rows:[{AccountID:1,ClientID:1}]} </code></pre> <p>And, on the client, my jqGrid looks like:</p> <pre><code>jQuery(document).ready(function () { $.ajax({ type: 'POST', url: '&lt;%: Url.Action("GetData", "Support") %&gt;', data: { query: 'foo' }, dataType: 'json', success: function (result) { alert(result.colNames); alert(result.colModel); alert(result.colData); jQuery('#QueryGrid').jqGrid({ jsonReader: { repeatitems: false }, shrinkToFit: true, datatype: 'jsonstring', colNames: result.colNames, colModel: result.colModel, datastr: result.colData, viewrecords: true }); }, error: function (x, e) { alert(x.readyState + ' ' + x.status + ' ' + e.msg); } }); }); </code></pre> <p>I have been putting this together based on a couple of related posts/replies here at Stack Overflow, as well as the jqGrid wiki. I am pretty sure that I am very, very close ... but it's just not working out.</p> <p>The problem I am having is that the jqGrid throws an error "Length of colNames &lt;> colModel!" and I can't seem to figure out what it is about my JSON strings that it doesn't like.</p> <p>Anyone see what I am missing here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload