Our pure JavaScript Scheduler component


Post by kerstin »

Hi,

Could you please advice which is the best way of reloading data into Bryntum Scheduler?
We want to set a timer that refreshes the data every 15th minute. It's huge amount of data, so backend request takes a while.
We would like to make the scheduler do the request silently in the background and when its finished ok replace the data in Scheduler.

Best regards,
Kerstin


Post by alex.l »

Hi kerstin,

If you have a big dataset, it might be useful to turn on https://bryntum.com/docs/scheduler/#Core/data/mixin/StoreSync#config-syncDataOnLoad . To sync data on background without load mask, you could use regular Ajax request and apply data on success:

await response = myAjaxRequest; 
response.success && (store.data = response.data);

But the best way, if it's possible, will be using WebSockets. We have a great demo here: https://bryntum.com/examples/scheduler/websockets/

All best,
Alex

All the best,
Alex


Post by kerstin »

Hi,

Thanks!

I am trying to use syncDataOnLoad and to set the new data, store.data = nnn.

I must do something wrong, the result is an javascript error "e.some is not a function". (e is an uglified variable)
Expanding the error:

 key: "data",
                set: function(e) {
                    var t = this;
                    if (t._thisIsAUsedExpression(t.plugins),
                    t.processConfiguredListeners(),
                    t.tree = !t.isChained && (t.tree || Boolean(t.autoTree && e && e.some((function(e) {
                        return e[t.modelClass.childrenField]
                    }
                    )))),

Can you give some advice?

BR,
Kerstin


Post by mats »

Can't help much without a proper test case I'm afraid. Please post one and we'll help out.


Post by henrikbackman »

This is what we do! We add a timer that after X amount of minutes trigger the Medinet.bryntum.update();

We get the last part (commented out) as the response but we then get an error from your script. Can you figure something out from the supplied code?

'use strict';

/* globals bryntum */

var Medinet = Medinet || {};

Medinet.bryntum = function() {

  var scheduler;

  return {
    init: function() {

  var element = document.getElementById('demo');

  scheduler = new bryntum.scheduler.Scheduler({
    id:             element + '_initialized',
    appendTo:       element,
    columns:        [
      {
        "field": "hospital", "text": "Sjukhus",
      }, {
        "field": "clinic", "text": "Klinik",
      }, {
        "field": "activity", "text": "Aktivitet",
      }, {
        "field": "category", "text": "Kategori",
      },
    ],
    startDate:      '2020-08-11',
    endDate:        '2020-08-11',
    features:       {
      group: false,
      sort: {...},
      timeRanges: {...},
      filter: {
        reapplyFilterOnAdd:     true,
        reapplyFilterOnUpdate:  true,
      },
      filterBar:        true,
      eventDrag:        false,
      eventDragCreate:  false,
      eventResize:      false,
      eventEdit:        false,
      eventEditor:      false,
    },
    crudManager:    {
      autoLoad: true,
      transport: {...},
      listeners: {
        loadfail: function() {...},
        requestdone: function(data) {...},
      },
    },
  });

},
update: function() {
  var xhr = new XMLHttpRequest();

  xhr.open('GET', [REQ_URL], true);
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

  xhr.onload = function() {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        var response = JSON.parse(xhr.responseText);

        scheduler.store.data = response;
      }
    }
  };

  xhr.send(null);
},
  };
}();

// Response is:
// {
//   "events":{
//     "rows":[
//       {
//         "endDate":"2020-08-11T16:30",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12666",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12666",
//         "name":"Mattias Frans",
//         "resourceId":"c-274_ar-33",
//         "startDate":"2020-08-11T08:00",
//         "text":"Mattias Frans"
//       },
//       {
//         "endDate":"2020-08-11T07:30",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12670",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12670",
//         "name":"Johanna Andersson",
//         "resourceId":"c-274_ar-34",
//         "startDate":"2020-08-10T16:30",
//         "text":"Johanna Andersson"
//       },
//       {
//         "endDate":"2020-08-12T07:30",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12663",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12663",
//         "name":"Kerstin Blomma",
//         "resourceId":"c-274_ar-34",
//         "startDate":"2020-08-11T16:30",
//         "text":"Kerstin Blomma"
//       },
//       {
//         "endDate":"2020-08-12T07:30",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12676",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12676",
//         "name":"Karl Kula",
//         "resourceId":"c-274_ar-34",
//         "startDate":"2020-08-11T16:30",
//         "text":"Karl Kula"
//       },
//       {
//         "endDate":"2020-08-11T16:30",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12671",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12671",
//         "name":"Johanna Andersson",
//         "resourceId":"c-274_a-77",
//         "startDate":"2020-08-11T08:00",
//         "text":"Johanna Andersson"
//       },
//       {
//         "endDate":"2020-08-11T16:30",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12677",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12677",
//         "name":"Karl Kula",
//         "resourceId":"c-274_a-77",
//         "startDate":"2020-08-11T08:00",
//         "text":"Karl Kula"
//       },
//       {
//         "endDate":"2020-08-12T08:00",
//         "event_details_url":"/oncall/popover/event_daily_details?customer_id=274&event_id=c-274_e-12674",
//         "event_num_oncall_time_comments":0,
//         "have_event_information":false,
//         "id":"c-274_e-12674",
//         "name":"Johanna Andersson",
//         "resourceId":"c-274_a-5",
//         "startDate":"2020-08-11T16:00",
//         "text":"Johanna Andersson"
//       }
//     ]
//   },
//   "header":"Dagens jourer",
//   "header_datestring":"Tisdag 11 augusti 2020",
//   "minVersionReq":4,
//   "resources":{
//     "rows":[
//       {
//         "activity":[
//           {
//             "className":"open-tooltip",
//             "link":"/oncall/popover/get_activity_daily?customer_id=274&selected_date=2020-08-11&activity_id=c-274_ar-33",
//             "text":"Prim\u00e4rjour"
//           }
//         ],
//         "category":[
// 
//         ],
//         "clinic":[
//           {
//             "link":"/oncall?layout=full&view=%2Foncall%2Fweekly&view_type=weekly&selected_date=2020-08-11&oncall_customer_id=274&action=selected",
//             "text":"Ortopedkliniken"
//           }
//         ],
//         "hospital":"",
//         "id":"c-274_ar-33"
//       },
//       {
//         "activity":[
//           {
//             "className":"open-tooltip",
//             "link":"/oncall/popover/get_activity_daily?customer_id=274&selected_date=2020-08-11&activity_id=c-274_ar-34",
//             "text":"Prim\u00e4rjour natt"
//           }
//         ],
//         "category":[
//           {
//             "link":"/oncall?layout=full&view=%2Foncall%2Fweekly&view_type=weekly&selected_date=2020-08-11&oncall_customer_id=274&category_id=35&action=selected",
//             "text":"Akuten"
//           }
//         ],
//         "clinic":[
//           {
//             "link":"/oncall?layout=full&view=%2Foncall%2Fweekly&view_type=weekly&selected_date=2020-08-11&oncall_customer_id=274&action=selected",
//             "text":"Ortopedkliniken"
//           }
//         ],
//         "hospital":"",
//         "id":"c-274_ar-34"
//       },
//       {
//         "activity":[
//           {
//             "className":"open-tooltip",
//             "link":"/oncall/popover/get_activity_daily?customer_id=274&selected_date=2020-08-11&activity_id=c-274_a-77",
//             "text":"Dagbakjour"
//           }
//         ],
//         "category":[
// 
//         ],
//         "clinic":[
//           {
//             "link":"/oncall?layout=full&view=%2Foncall%2Fweekly&view_type=weekly&selected_date=2020-08-11&oncall_customer_id=274&action=selected",
//             "text":"Ortopedkliniken"
//           }
//         ],
//         "hospital":"",
//         "id":"c-274_a-77"
//       },
//       {
//         "activity":[
//           {
//             "className":"open-tooltip",
//             "link":"/oncall/popover/get_activity_daily?customer_id=274&selected_date=2020-08-11&activity_id=c-274_a-5",
//             "text":"Jourvecka 1"
//           }
//         ],
//         "category":[
// 
//         ],
//         "clinic":[
//           {
//             "link":"/oncall?layout=full&view=%2Foncall%2Fweekly&view_type=weekly&selected_date=2020-08-11&oncall_customer_id=274&action=selected",
//             "text":"Ortopedkliniken"
//           }
//         ],
//         "hospital":"",
//         "id":"c-274_a-5"
//       }
//     ]
//   },
//   "selected_date":"2020-08-11",
//   "success":true
// }

Post by Maxim Gorkovsky »

Hello.
If response has structure:

{ "resources": { "rows": [...] } }

then do load store data you should call:

scheduler.store.data = response.resources.rows

Post by henrikbackman »

Hi, great that works. In your documentation it says that the filter (using filterBar) will be reapplied after the store data added. It's doesn't behave that way for us. Is that a bug or is it something we need to do?


Post by Maxim Gorkovsky »

Filter should be reapplied. I have just tried it on the filtering demo (with filter bar).
Navigate to the demo, type da to resource name filter, then open console and run

scheduler.store.data = [{ name : 'foo' }, { name : 'fonda' }]

You'll see filter reapplied.

Can you reproduce the issue on our demos?


Post Reply