Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <table dojoType="dojox.grid.DataGrid">
  2. <thead>
  3. <tr>
  4. <th field="id">ID</th>
  5. <th field="contact.name">Name</th>
  6. <th field="contact.tel">Telephone</th>
  7. <th field="contact.birthdate.time">Birthday</th>
  8. </tr>
  9. </thead>
  10. </table>
  11.  
  12. [{
  13. 'id':1,
  14. 'contact':{
  15. 'name':'Doh',
  16. 'firstname':'John',
  17. 'tel':'123-123456',
  18. 'birthdate':{
  19. 'javaClass':'java.sql.Timestamp',
  20. 'time':1234567893434}}
  21. }]
  22.  
  23. <table dojoType="dojox.grid.DataGrid">
  24. <thead>
  25. <tr>
  26. <th field="id">ID</th>
  27. <th field="contact" get="myGrid.getContactName">Name</th>
  28. <th field="contact" get="myGrid.getContactTel">Telephone</th>
  29. <th field="contact" get="myGrid.getContactBirthdateTime">Birthday</th>
  30. </tr>
  31. </thead>
  32. </table>
  33.  
  34. myGrid.getContactName = function(colIndex,item){
  35. return item.name;
  36. };
  37.  
  38. myGrid.getContactName = function(colIndex,record){
  39. if(record)return record.contact.name;
  40. else return null;
  41. };
  42.  
  43. dgc._Base.markupFactory = function(node, cellDef){
  44. var d = dojo;
  45. ...
  46. var comparator = d.trim(d.attr(node,"comparator")||"");
  47. if(comparator){
  48. cellDef.comparator = dojo.getObject(comparator);
  49. }
  50. ...
  51. }
  52.  
  53. getSortProps:function(){
  54. ...
  55. return[{attribute:c.field,descending:desc,comparator:c.comparator}];
  56. }
  57.  
  58. function execute(array){
  59. // execute the whole query, first we filter
  60. var results = dojo.filter(array, query);
  61. // next we sort
  62. if(options && options.sort){
  63. results.sort(function(a, b){
  64. for(var sort, i=0; sort = options.sort[i]; i++){
  65. var aValue = a[sort.attribute];
  66. var bValue = b[sort.attribute];
  67. if (aValue != bValue) {
  68. // changed Part start
  69. if(options.sort[i].comparator){
  70. return !!sort.descending == options.sort[i].comparator(aValue,bValue) ? -1 : 1;
  71. }
  72. else{
  73. return !!sort.descending == aValue > bValue ? -1 : 1;
  74. }
  75. // changed Part end
  76. }
  77. }
  78. return 0;
  79. });
  80. }
  81. ...
  82. return results;
  83. }
  84.  
  85. ...
  86. <td field="myArray" get="getsNameFromArray" comparator="comparesNames">Name</td>
  87. ...
  88.  
  89. compareNames = function(a,b){
  90. return a.name > b.name;
  91. }
  92.  
  93. getNamesFromArray= function(idx,record){
  94. return record.myArray.name;
  95. }
  96.  
  97. ...
  98. <th field="contact" get=myGrid.getContactName>Name</th>
  99. ...
Add Comment
Please, Sign In to add comment