Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by sp on Apr 24, 2009 06:21
open dhtmlx forum
JSON format for grid header?

When loading a grid via XML, we can define column headers and other grid attributes with the following syntax:

    <head>
        <beforeInit>
            <call command="methodName"><param>string value</param></call>
        </beforeInit>
        <afterInit>
            <call command="methodName"><param>string value</param></call>
        </afterInit>

        <column width="..." type="..." align="..." sort="...">Header1</column>        
        <column width="..." type="..." align="..." sort="...">Header2</column>        
        <column width="..." type="..." align="..." sort="...">Header3</column>        

        <settings>
...
        </settings>
    </head>

Is this supported with json-based loading? If so, what's the syntax for the JSON equivalent to this?
Answer posted by dhxSupport on Apr 24, 2009 06:43
Unfortunately JSON format doesn't support grid header. If you load grid via JSON format you should set grid's header via API: mygrid.setHeader(); mygrid.setInitWidths();
Answer posted by sp on Apr 24, 2009 09:06
Thanks for the reply... is this feature planned for a future release?  We're moving our codebase to json-based rendering, but a significant portion of it uses dynamic headers.  I'd hate to have to move all that logic to the JS side.
Answer posted by Alex (support) on Apr 25, 2009 00:48

Unfortunately, this feature won't be implemented in the next release.

So, you can initialize grid (set its header) from xml and load rows from json:

mygrid = new dhtmlXGridObject('gridbox');
...
mygrid.load("header.xml",function(){

  mygrid.load("data.json","json");
 })

Where header.xml is:

<rows>

  <head> 
  <beforeInit> 
  <call command="methodName"><param>string value</param></call> 
  </beforeInit> 
  <afterInit> 
  <call command="methodName"><param>string value</param></call> 
  </afterInit> 
  <column width="..." type="..." align="..." sort="...">Header1</column>  
  <column width="..." type="..." align="..." sort="...">Header2</column>  
  <column width="..." type="..." align="..." sort="...">Header3</column>  

  <settings> 
... 
  </settings> 
  </head>
</rows>