dojo - When declaratively creating a dojox.grid.DataGrid - how to specify nested data in the field attribute? -


i'm creating dojox.grid.datagrid in dojo 1.6 following notation:

<table dojotype="dojox.grid.datagrid">   <thead>     <tr>       <th field="id">id</th>       <th field="contact.name">name</th>       <th field="contact.tel">telephone</th>       <th field="contact.birthdate.time">birthday</th>     </tr>   </thead> </table> 

the data looks this:

[{ 'id':1, 'contact':{   'name':'doh',    'firstname':'john',   'tel':'123-123456',   'birthdate':{     'javaclass':'java.sql.timestamp',     'time':1234567893434}} }] 

id rendered corectly, others render "...". have tried specify formatter, setting base object "contact" field , returning field.name example. works in far correct value displayed, sorting uses base object.

i think there might way push further, overriding sorting of table, keep simple possible.

also wish prevent performance issues popping up.

any ideas?

i have found out there attribute datagrid row definition called "get". "get" specifies name of function returnes value displayed in datagrid column.

theoretically should solve problem.

the get-function implemented in following way:

grid definition:

<table dojotype="dojox.grid.datagrid">   <thead>     <tr>       <th field="id">id</th>       <th field="contact" get="mygrid.getcontactname">name</th>       <th field="contact" get="mygrid.getcontacttel">telephone</th>       <th field="contact" get="mygrid.getcontactbirthdatetime">birthday</th>     </tr>   </thead> </table> 

callback function (example):

mygrid.getcontactname = function(colindex,item){   return item.name; }; 

i can not tell @ moment if implementation correct, since item parameter null in application.

this due use of new store api (store.memory) instead of itemfilereadstore, have not been successfull in solving puzzle yet.

also not able test gird sorting new approach, not flag sollution resolved yet.

update

mygrid.getcontactname = function(colindex,record){   if(record)return record.contact.name;   else return null; }; 

once averted null case worked fine way.

however client sort of grid doesn't seem access through function uses field directly. prevents correct sorting on nested fields.

update

i got sollution problems:

the first problem : specifying nested data datagrid fields solved allready using get-function dive arrays substructure. (that explained above)

sorting still dependent on field attribute. if field attribute contains name of array column not sort correctly.

i had modify few dojo classes accomodate that. later put in more modular form, here raw result now:

first needed allow definition of addtional comparator callback in grid definition. have added code dojox.grid.cells._base

dgc._base.markupfactory = function(node, celldef){ var d = dojo; ... var comparator = d.trim(d.attr(node,"comparator")||""); if(comparator){   celldef.comparator = dojo.getobject(comparator); } ... } 

next datagrid needs give new parameter query sorting. done in dojox.grid.datagrid. "c" cell modified above.

getsortprops:function(){ ... return[{attribute:c.field,descending:desc,comparator:c.comparator}]; } 

finally need change sorting defined in dojo.store.util.simplequeryengine. simplequeryengine default engine memorystore (dojo.store.memory).

function execute(array){     // execute whole query, first filter     var results = dojo.filter(array, query);     // next sort     if(options && options.sort){         results.sort(function(a, b){             for(var sort, i=0; sort = options.sort[i]; i++){                 var avalue = a[sort.attribute];                 var bvalue = b[sort.attribute];                 if (avalue != bvalue) {                     // changed part start                     if(options.sort[i].comparator){                          return !!sort.descending == options.sort[i].comparator(avalue,bvalue) ? -1 : 1;                     }                     else{                         return !!sort.descending == avalue > bvalue ? -1 : 1;                     }                     // changed part end                 }             }             return 0;         });     }     ...     return results; } 

now can add comparators each column , define them want to:

declarative datagrid setup:

... <td field="myarray" get="getsnamefromarray" comparator="comparesnames">name</td> ... 

javascript definition of comparator function (a , b "myarray" objects):

comparenames = function(a,b){   return a.name > b.name; } 

javascript definition of getter function (record whole row , contains "myarray" object):

getnamesfromarray= function(idx,record){   return record.myarray.name; } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -