How to remove datasource from another datasource?

4 posts, 0 answers
  1. 宏吉
    宏吉 avatar
    40 posts
    Member since:
    Mar 2017

    Posted 27 Jul 2017 Link to this post

    I use the script like 'ex1' but it will very slow when the event is too much,so I want use pushDestroy to remove events from another datasource like 'ex2' but not useful

    ex1:

    function remove(ownerId){

    var raw = $("#scheduler").data("kendoScheduler").dataSource.data();

    var length = raw.length;

    var item, i;

    for(i=length-1; i>=0; i--){

         item = raw[i];

         if (item.ownerId==ownerId)

         { $("#scheduler").data("kendoScheduler").dataSource.remove(item); }

    }

    }

    ex2:

     var sharableDataSource = new kendo.data.SchedulerDataSource({
                transport: {
                    read: {

                        url: "/api/tasks",
                        data: { id: id }
                    }
                },
                schema: {
                    model: {
                        id: "TaskID",
                        fields: {
                            eventID: { from: "EventID" },
                            taskID: { from: "TaskID" },
                            title: { from: "Title", validation: { required: true } },
                            location: { from: "Location" },
                            start: { type: "date", from: "Start" },
                            end: { type: "date", from: "End" },
                            description: { from: "Description" },
                            recurrenceId: { from: "RecurrenceID" },
                            recurrenceRule: { from: "RecurrenceRule" },
                            recurrenceException: { from: "RecurrenceException" },
                            ownerId: { from: "OwnerID"},
                            isAllDay: { type: "boolean", from: "IsAllDay" },
                            alert: { from: "Alert", type: "object", defaultValue: "" },
                            showfor: { from: "Showfor", type: "object", defaultValue: "busy" },
                        }
                    }
                }
            });

    $("#scheduler").data("kendoScheduler").dataSource.pushDestroy(sharableDataSource.data().toJSON());

  2. Tyler
    Tyler avatar
    19 posts
    Member since:
    Jul 2017

    Posted 27 Jul 2017 in reply to 宏吉 Link to this post

    In ex2, you don't specify data for your dataSource. The data in read sends parameters to your remote service. Here is documentaiton on the dataSource: http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read.data

    $("#scheduler").data("kendoScheduler").dataSource.pushDestroy(sharableDataSource.data().toJSON()); will correctly 'remove' (without marking them as removed) all data in sharableDataSource.data() that is in the scheduler dataSource, however, you have to put data into sharableDataSource, which you are not doing.

    DataSource has a specific data field, data isn't set with the read data field.

  3. Tyler
    Tyler avatar
    19 posts
    Member since:
    Jul 2017

    Posted 27 Jul 2017 in reply to Tyler Link to this post

    Here is a Dojo that has a simple dataSource that does what you want to do in ex2. Note the dataSource data field.
  4. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1201 posts

    Posted 31 Jul 2017 Link to this post

    Hi Hung-Chi,

    The remove() method of the Kendo dataSource will mark the items as dirty, so they will also be removed from the remote DataSource. On the other hand, the pushDestroy() method would only remove the events from the local instance of the DS. The items on the remote would not be affected and no calls will be sent.

    This is the reason for the difference in the performance, when using the two different methods.

    If you need to improve performance and at the same time remove items on the remote too, I would suggest you to enable the batch editing option of the DataSource, iterate over the items as on example 1 and call the sync() method to send the changes to the remote:
    dataSource: {
        batch: true,
    .........
    and:
    function remove(ownerId){
       var dataSource = $("#scheduler").data("kendoScheduler").dataSource;
        var raw = dataSource.data();
        var length = raw.length;
        var item, i;
       
        for(i=length-1; i>=0; i--){
             item = raw[i];
             if (item.ownerId==ownerId){
                 dataSource.remove(item);
             }
        }
         
        dataSource.sync();
    });

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top