search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to collapse tasks based on field from database

Asked by Anonymous
2 months ago.

Hi, my gantt information comes from a database and i added a field called collapsed with a boolean value. I want to preeminently collapse rows with a true value in that field.

My problem is when I try to do this in onBeofreTaskRendered like this:

 dp.onBeforeTaskRender = function (args) {
                dp.tasks.find(args.data.id).row.collapse();
                args.data.box = { bubbleHtml: args.data.box, cssClass: args.data.CssClass };
                args.data.row = { bubbleHtml: args.data.row };
                args.data.cssClass = args.data.CssClass;
            };

I get this error:

Uncaught TypeError: Cannot read properties of null (reading 'toggle')
    at o.expanded (daypilot-all.min.js:14:12102)
    at o.collapse (daypilot-all.min.js:14:12223)
    at dp.onBeforeTaskRender (<anonymous>:149:49)
    at s.Jh (daypilot-all.min.js:72:913)
    at s.Ih (daypilot-all.min.js:72:2784)
    at s.xh (daypilot-all.min.js:72:326)
    at daypilot-all.min.js:68:6291

Even though when I try to check whether a given task’s row is expanded buy running:

 console.log(dp.tasks.find(args.data.id).row.expanded());

I do get a value. From what I gather, the code that toggles and/or collapses tasks is creating an error but when I try to call it elsewhere in the code (outside the before render event), it doesn’t work either.

Answer posted by Dan Letecky [DayPilot]
2 months ago.

In onBeforeTaskRender, it is only possible to access the raw data object (args.data). The DayPilot.Task object is not available yet.

To collapse the rows, you can set the args.data.row.collapsed property there:

dp.onBeforeTaskRender = function (args) {
  // ...
  args.data.row = { bubbleHtml: args.data.row, collapsed: true };
  // ...
};
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.