This is a migrated thread and some comments may be shown as answers.

How to remove datasource from another datasource?

3 Answers 484 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
宏吉
Top achievements
Rank 1
宏吉 asked on 27 Jul 2017, 08:04 AM

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());

3 Answers, 1 is accepted

Sort by
0
Tyler
Top achievements
Rank 1
answered on 27 Jul 2017, 04:48 PM

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.

0
Tyler
Top achievements
Rank 1
answered on 27 Jul 2017, 04:50 PM
Here is a Dojo that has a simple dataSource that does what you want to do in ex2. Note the dataSource data field.
0
Veselin Tsvetanov
Telerik team
answered on 31 Jul 2017, 06:43 AM
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.
Tags
Scheduler
Asked by
宏吉
Top achievements
Rank 1
Answers by
Tyler
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or