jQWidgets Forums

jQuery UI Widgets Forums Grid Dynamic Column

This topic contains 2 replies, has 2 voices, and was last updated by  fredmichel 10 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Dynamic Column #68507

    fredmichel
    Participant

    Hi,

    I am trying to do something Dynamic with the JqXGrid and SQL, and I wonder if it is Possible.

    In My Code Below I would like to pass an array of Column Names to the Function on order to build the headers in the columns: section….

    Since I don’t know how many columns will be in my Array, I thought about looping and dynamically create each header…but it gives me an error message the minute I add the For Loop. Maybe I am doing this completely Wrong…but anybody know if it is possible with JqxGrid? If Yes, can you assist me with it please?

    Thanks a lot.

    <script type="text/javascript">
    		
    function DynamicGrid(array) 
    				{					       
                    	$("#DynamicGrid").jqxGrid(
                		{
                    		width: 850,
                    		//source: dataAdapter,
                    		columnsresize: true,
                    		columns: 
    						[
                        		                {for (j = 0; j < array.length; j++) { 
        						     { text: array[i], datafield: array[i], width: 250 },
    						}				
    							
                   			]
                		});
    				}				
    	</script>
    Dynamic Column #68521

    Peter Stoev
    Keymaster

    Hi fredmichel,

    The provided code will not work. columns expect Array, not loop. If you want to update the columns dynamically, you can set the Grid’s columns property like that $(“#grid”).jqxGrid({columns: newColumnsArray}) or you can also check this sample: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/dynamiccolumns.htm?arctic

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    Dynamic Column #68826

    fredmichel
    Participant

    Thanks a lot Peter 😉

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.