如何过滤dojo分类的treeGrid?

时间:2018-07-01 21:19:35

标签: javascript dojo dojox.grid.datagrid dojox.grid

我有可以正常工作的dojo treeGrid。它显示了按年份对成本进行分类的项目。还显示总计。但是,当我尝试按列之一对其进行过滤时,它会弄乱网格(破坏类别并不适当地过滤记录)。我是否可以正确使用grid.filter?我需要保持分类结构,但删除/过滤某些记录。还是应该以某种方式刷新jsonStore?

//HTML
<div id="treeGrid"></div>

<a href="javascript:void(0)">
    <span id='button1'>Filter</span>
</a>


//JavaScript
var layout = [ 
    { cells: [ 
       [ {field: "year", name: "Year"}, 
         {field: "childItems", 
           children: [ { field: "status", name: "Status"}, 
                       { field: "programname", name: "Program Name"}, 
                       { field: "programcost", name: "Program Cost"}
                     ], 
                  aggregate: "sum" 
                  } 
                  ]] } ]

var jsonStore = new dojo.data.ItemFileWriteStore({ url: "<........>"});

var grid = new dojox.grid.TreeGrid({ 
    structure: layout, 
    store: jsonStore, 
    query: {type: 'year'}, 
    queryOptions: {deep: true},
    rowSelector: true, 
    openAtLevels: [false],
    autoWidth: true,
    autoHeight: true
    }, 
    dojo.byId("treeGrid"));


    /* attach an event handler */
on(dom.byId("button1"),'click',
    function(e){
        grid.filter({status: "Approved"});
    }
   );


grid.startup();

dojo.connect(window, "onresize", grid, "resize");


/* sample data ======================================================
{
  "identifier": "id",
  "label": "name",
  "items": [
    {
      "id": "2018",
      "type": "year",
      "year": "2018",
      "childItems": [
        {
          "status": "Approved",
          "programname": "Program 1",
          "programcost": 100
        },
        {
          "status": "Pending",
          "programname": "Program 2",
          "programcost": 200
        }
      ]
    },
    {
      "id": "2016",
      "type": "year",
      "year": "2016",
      "childItems": [
        {
          "status": "Pending",
          "programname": "Program 3",
          "programcost": 300
        }
      ]
    }
  ]
}
*/

0 个答案:

没有答案