angularjsfullcalendarfullcalendar-scheduler

Set resourceOrder dynamically after the scheduler was rendered


I'm using the fullCalendar Scheduler in an Angular 1.5 application.

I wrapped it into a directive and inside the directive I have a config object with all the properties

var calendarConfig = {
  schedulerLicenseKey: '----------------------------',
  resources: function (callback) {
    scope.getResources()(callback);
  },
  resourceColumns: [
    {
      labelText: 'Name',
      field: 'name'
    },
    {
      labelText: 'Id',
      field: 'id',
      width: "85px"
    }
  ],
  resourceOrder: "name",
  defaultView: "timelineMonth",
  resourceLabelText: "Test",
  resourceAreaWidth: "17%",
  aspectRatio: '100%',
  header: {
    left: 'reorderBtn',
    center: 'title',
    right: 'prev next'
  },
  customButtons: {
    sortName: {
      text: 'reorderBtn',
      click: function (oEvent) {
        ---------- how to perform the reordering inside here ? ----
      }
    }
  },
  eventClick: eventClick,
  dayClick: dayClick,
  viewRender: viewRender,
  weekNumbers: true,
};

I noticed that scheduler has a property called "resourceOrder" which works nice at initialization.

My use case is when I press the button I would like to see the resources sorted by the name descending.

I tried to use

$(element).fullCalendar('getView').options.resourceOrder = "-name"
$(element).fullCalendar('render')

but it does not work.

I can sort the resources outside the directive manually and then reset the sorted resources again as a source, but I would like to avoid this and make use of the nice property "resourceOrder" that scheduler provides.

Any ideas? Or any best-practices on how to sort the resources by one column at a time?


Solution

  • You can set or get fullCalendar options dynamicaly using fullCalendar setters and getters.

    In your case:

    $('#calendar').fullCalendar('option', 'resourceOrder', '-name');