How to filter dojo categorized treeGrid?

泪湿孤枕 提交于 2019-12-11 15:07:02

问题


I have dojo treeGrid that works fine. It shows projects with cost categorized by year. Also it shows totals. But when I try to filter it by one of column it mess up the grid (breaks categories and filter records improperly). Do I use grid.filter properly? I need to keep categorized structure but remove/filter certain records. Or should I refresh jsonStore somehow instead?

//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
        }
      ]
    }
  ]
}
*/

来源:https://stackoverflow.com/questions/51127103/how-to-filter-dojo-categorized-treegrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!