<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: Dynamic colNames and ColModel</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/dynamic-colnames-and-colmodel</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/dynamic-colnames-and-colmodel/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>luismartin on Dynamic colNames and ColModel</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/dynamic-colnames-and-colmodel#p27792</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/dynamic-colnames-and-colmodel#p27792</guid>
        	        	<description><![CDATA[<p>Hello, I&#39;m new to this jquery plugin. I decided to use it among many others because this one looks the most</p>
<p>powerful. However I&#39;m having problems to get it working.</p>
</p>
<p>First of all, as said in the topic, since the content will be served from the server (PHP), and I want to use it to</p>
<p>display different lists of items, I need that both properties colNames and colModel will be served dynamically.</p>
<p>So, this is how I set it up in a js file:</p>
</p>
<pre>$(document).ready(function() {
    $("#listing").jqGrid({
    	datatype: "clientSide",
    	height: 500,
        colNames: namesList,
        colModel: modelList,
       	multiselect: true,
        viewrecords: true,
       	caption: "Test"
    });
});</pre>
</p>
<p>Here&#39;s an example in PHP of an item type whose records must be listed. I set its corresponding column</p>
<p>names and how will they be displayed:</p>
<pre>$colNames = array(&#39;Id&#39;, &#39;Title&#39;, &#39;Featured&#39;, &#39;Language&#39;, &#39;Date created&#39;, &#39;Date modified&#39;,&#160;</pre>
<pre>&#39;Date published&#39;, &#39;Status&#39;);
        $colModel = array(
            array(&#39;name&#39; =&#62; &#39;id_article&#39;, &#39;id&#39; =&#62; &#39;id_article&#39;, &#39;width&#39; =&#62; 60, &#39;sorttype&#39; =&#62; &#39;int&#39;),
            array(&#39;name&#39; =&#62; &#39;title&#39;, &#39;id&#39; =&#62; &#39;title&#39;, &#39;width&#39; =&#62; 450, &#39;sorttype&#39; =&#62; &#39;text&#39;),
            array(&#39;name&#39; =&#62; &#39;featured&#39;, &#39;id&#39; =&#62; &#39;featured&#39;, &#39;width&#39; =&#62; 60, &#39;sorttype&#39; =&#62; &#39;int&#39;),
            array(&#39;name&#39; =&#62; &#39;language&#39;, &#39;id&#39; =&#62; &#39;language&#39;, &#39;width&#39; =&#62; 60, &#39;sorttype&#39; =&#62; &#39;text&#39;),
            array(&#39;name&#39; =&#62; &#39;date_c&#39;, &#39;id&#39; =&#62; &#39;date_c&#39;, &#39;width&#39; =&#62; 120, &#39;sorttype&#39; =&#62; &#39;date&#39;),
            array(&#39;name&#39; =&#62; &#39;date_m&#39;, &#39;id&#39; =&#62; &#39;date_m&#39;, &#39;width&#39; =&#62; 120, &#39;sorttype&#39; =&#62; &#39;date&#39;),
            array(&#39;name&#39; =&#62; &#39;date_p&#39;, &#39;id&#39; =&#62; &#39;date_p&#39;, &#39;width&#39; =&#62; 120, &#39;sorttype&#39; =&#62; &#39;date&#39;),
            array(&#39;name&#39; =&#62; &#39;status&#39;, &#39;id&#39; =&#62; &#39;status&#39;, &#39;width&#39; =&#62; 60, &#39;sorttype&#39; =&#62; &#39;int&#39;)
        );</pre>
<p>This is how I dynamically create the variables I need for colNames, colModel and the data to display</p>
<p>(enclosed&#160;with script tags):</p>
</p>
<pre>var namesList = &#60; ?php echo json_encode($colNames)  ? &#62;, 
    modelList = &#60; ?php echo json_encode($colModel)  ? &#62;, 
    data = &#60; ?php echo json_encode($lista)  ? &#62; 
    
for(var i = 0; i &#60;= datos.length; i++) {
    $(&#39;#listing&#39;).addRowData(i+1, data[i]);
}
</pre>
<p>With this all configured, I just get to build the background of the grid with the column names.</p>
<p>No data is&#160;displayed. Could you please help me?</p>
]]></description>
        	        	<pubDate>Tue, 27 Nov 2012 14:59:18 +0200</pubDate>
        </item>
</channel>
</rss>