0

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
        }
      ]
    }
  ]
}
*/
4
  • Can you add some sample data in the example?
    – Himanshu
    Commented Jul 3, 2018 at 3:19
  • just added sample data to the very bottom. Thank you Himanshu
    – John Glabb
    Commented Jul 3, 2018 at 3:39
  • After an hour of hit and try, I think the problem is that not all your data fields have the idAttribute name. I have created a fiddle in which filtering and changing of store (related to this ) is working. You may notice that I have used model as an interface between store and grid. And to change the store, I have created a new model and changed the model. Also notice, that grid._refresh() does not have any effect. The changes are reflected without it as well.
    – Himanshu
    Commented Jul 4, 2018 at 4:26
  • Sorry for the typo, the idAttribute is id and not name.
    – Himanshu
    Commented Jul 4, 2018 at 4:32

0