retrieve a list- from the datasource

Posted by refael shira on 23-Aug-2016 07:09

Hi,

I would like to know how I can retrieve a list- from the datasource in a way that it'll be in a specific order, that I decide- according to a specific field.

for example according to the date.

I want to get all the items in the datasource, but I want them to be displayed in such a way that the first item will be the one with the earliest date, and the last one with the last date.

regards,

Shira Taytelbaom

All Replies

Posted by Vimalkumar Selvaraj on 23-Aug-2016 07:56

Hi Shira,

I assume you are asking about Kendo data source. You can  apply a sorting (asc) on Datasource by Date field thus results your data to ascending order. I put a small code to achieve

var dataSource = new kendo.data.DataSource({

 data: [

   { name: "Xyz", age: 33 , dob:'04/04/1990'},

   { name: "Jane Doe", age: 30 , dob:'04/27/1988' },

 ],

 sort: { field: "dob", dir: "asc" }, //Apply sorting by dob field

 schema:{

   model:{

fields:{

 dob:{type:'date'}, //Make sure you define a build with correct data type

 name:{type:'string'},

 age:{type:'number'}

}

}

 }

});

dataSource.fetch(function(){

 var data = dataSource.view(); //Get sorted order

 console.log(data[0].dob); // displays "27/04/1988"

 var actualData = dataSource.data(); //Get inserted order

 console.log(actualData[0].dob); // displays "04/04/1990"

});

Kindly refer this url for more details 

docs.telerik.com/.../datasource

Hope this helps,

Thanks,

Vimal.

Posted by Shira Taytelbaom on 23-Aug-2016 09:18
Thank you very much!

But I want to do the sort on a dataSource that I have, 
Can I do such a thing like  :

data: [ {dataSource},],
and then the rest
the sort, schema, etc...

Thanks a lot,
Shira

Posted by Vimalkumar Selvaraj on 23-Aug-2016 09:31

Hi,

You can apply a sort on your dataSource as well in same way how i demonstrated in example. You don't require to create another instance of DataSource . You can call sort method on your dataSource instance, say for an example

dataSource.sort({ field: "dob", dir: "asc" });

Make sure your dataSource instance is having proper schema,model defined. Or if you want to create new Data Source instance by using another dataSource

do like this

var newDataSource = new kendo.data.DataSource({

  data:dataSource.data(), // get data from your own dataSource Instance

  schema:{

      model:{

           fields:{

            }

      }

  }

})

If you need more details kindly create Rollbase App by explaining your requirement , that way we can help you faster.

Thanks,

Vimal.

Posted by Shira Taytelbaom on 23-Aug-2016 09:42
THANK YOU SO MUCH!!!
You really helped me! It works now!!


Posted by Shira Taytelbaom on 23-Aug-2016 11:02
The problem is that I need to have one list- that is complexed from few dataSources, and there I need all the items to be sorted by the date!!!!
How can I do it?
- Is there a way to combine all dataSources to One different new DataSource??
THANKS A LOT,
Shira

Posted by Vimalkumar Selvaraj on 23-Aug-2016 11:32

Hi Shira,

It should be straight forward, you should get data from both DataSources and merge them and use that in your new Data Source.  I assume all 3 Datasources schema model will be same

var data1 = dataSource1.data(); //First data source data

var data2 = dataSource2.data(); //Second data source data

//concat two array data by converting kendo model to actual json

var mergedData = data1.toJSON().concat(data2.toJSON());

var newDataSource = new kendo.data.DataSource({

 data:mergedData,

 sort:{field:'dob',dir:'asc'},

 schema:{

   model:{

fields:{

 dob:{type:'date'},

 name:{type:'string'},

 age:{type:'number'}

}

}

 }

});

newDataSource.fetch(function(){

 var data = newDataSource.view();

 console.log(data[0].dob);

});

Hope this helps,

Thanks,

Vimal.

Posted by Shira Taytelbaom on 24-Aug-2016 03:00
Hi,
Thanks a lot,
This is exactly what I need.
I don't know why it seems like it doesn't work well,
I tried to do the "mergeData" and then to insert this data to a new DataSource, as you wrote,
But the newDataSource seems to be empty...
And also after this following code:
"var mergedData = data1.toJSON().concat(data2.toJSON());"
The mergedData seems to be empty....
Do you know what can cause the issue?
Thanks a lot for all your help!!
Have a great day!
Shira

Posted by Vimalkumar Selvaraj on 24-Aug-2016 03:10

Hi Shira,

Do you have data in your first and second Datasources?. Could you try to print data1 and data2 in console and see if that has data or empty array?.

May i know how you are creating your first and second DataSources?.  If you are creating from local or json Data you should call dataSource.fetch() method to load your json data into datasources instance.

Thanks,

Vimal.

Posted by Shira Taytelbaom on 24-Aug-2016 03:34
Hi,
I do it in JSON,
But I don't know what's wrong...
I copied here the index of the page that I ork on, (it's quite long),
But I guess the important part is in "onShow" function that is written by the end- there I added the code you sent me!
But I added the all page- because maybe you'll be able to see what's wrong, maybe according to all the definitions in the begininng....
Thanks a lot!!!!!!

Here is the index page:


'use strict';
app.allWorkPlans = kendo.observable({
    onShow: function () { },
    afterShow: function () { },
    isUpdated: false,
    showEditDelete: true,
});
var aarr = {};
var aarr1 = {};
var aarr2 = {};
var aarr3 = {};
var aarr4 = {};
var aarr5 = {};
//var data1;
//var data2;

(function (parent) {
    var subject = {};
    var status = {};

    var object, a;
    var id, uid;
    var dataProvider = app.data.progressDataProvider,
         fetchFilteredData = function (paramFilter, searchFilter) {
             var model = parent.get('homeModel'),
                 dataSource = model.get('dataSource');
             //dataSource1 = model.get('dataSource1');

             if (paramFilter) {
                 model.set('paramFilter', paramFilter);
             } else {
                 model.set('paramFilter', undefined);
             }

             if (paramFilter && searchFilter) {
                 dataSource.filter({
                     logic: 'and',
                     filters: [paramFilter, searchFilter]
                 });
             } else if (paramFilter || searchFilter) {
                 dataSource.filter(paramFilter || searchFilter);
             } else {
                 dataSource.filter({});
             }

             //maybe here i can try to add more data sources

             //dataSource = model.get('dataSource1');
             ////dataSource1 = model.get('dataSource1');

             //if (paramFilter) {
             //    model.set('paramFilter', paramFilter);
             //} else {
             //    model.set('paramFilter', undefined);
             //}

             //if (paramFilter && searchFilter) {
             //    dataSource.filter({
             //        logic: 'and',
             //        filters: [paramFilter, searchFilter]
             //    });
             //} else if (paramFilter || searchFilter) {
             //    dataSource.filter(paramFilter || searchFilter);
             //} else {
             //    dataSource.filter({});
             //}

         },

          processImage = function (img) {

              if (!img) {
                  var empty1x1png = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQI12NgYAAAAAMAASDVlMcAAAAASUVORK5CYII=';
                  img = 'data:image/png;base64,' + empty1x1png;
              }

              return img;
          },

        jsdoOptions = {
            name: 'kabat_training_task',
            autoFill: false
        },
        jsdoOptions1 = {
            name: 'kabat_school_Guidelines_task',
            autoFill: false
        },
         jsdoOptions2 = {
             name: 'Emergency_Drill',
             autoFill: false
         },
          jsdoOptions3 = {
              name: 'kabat_kindergarden_training_task',
              autoFill: false
          },
           jsdoOptions4 = {
               name: 'kabat_kindergarten_Guidelines_task',
               autoFill: false
           },
            jsdoOptions5 = {
                name: 'kindergarden_Emergency_Drill',
                autoFill: false
            },
        dataSourceOptions = {
            type: 'jsdo',
            transport: {},
            schema: {
                model: {
                    fields: {
                        'dueDate': {
                            field: 'dueDate',
                            defaultValue: ''
                        },
                    }
                }
            },
            serverFiltering: true,
            serverSorting: true,
            serverPaging: true,
            pageSize: 50
        },
         dataSourceOptions1 = {
             type: 'jsdo',
             transport: {},
             schema: {
                 model: {
                     fields: {
                         'dueDate': {
                             field: 'dueDate',
                             defaultValue: ''
                         },
                     }
                 }
             },
             serverFiltering: true,
             serverSorting: true,
             serverPaging: true,
             pageSize: 50
         },
         dataSourceOptions2 = {
             type: 'jsdo',
             transport: {},
             schema: {
                 model: {
                     fields: {
                         'subject': {
                             field: 'subject',
                             defaultValue: ''
                         },
                     }
                 }
             },
             serverFiltering: true,
             serverSorting: true,
             serverPaging: true,
             pageSize: 50
         },
         dataSourceOptions3 = {
             type: 'jsdo',
             transport: {},
             schema: {
                 model: {
                     fields: {
                         'subject': {
                             field: 'subject',
                             defaultValue: ''
                         },
                     }
                 }
             },
             serverFiltering: true,
             serverSorting: true,
             serverPaging: true,
             pageSize: 50
         },
         dataSourceOptions4 = {
             type: 'jsdo',
             transport: {},
             schema: {
                 model: {
                     fields: {
                         'subject': {
                             field: 'subject',
                             defaultValue: ''
                         },
                     }
                 }
             },
             serverFiltering: true,
             serverSorting: true,
             serverPaging: true,
             pageSize: 50
         },
         dataSourceOptions5 = {
             type: 'jsdo',
             transport: {},
             schema: {
                 model: {
                     fields: {
                         'subject': {
                             field: 'subject',
                             defaultValue: ''
                         },
                     }
                 }
             },
             serverFiltering: true,
             serverSorting: true,
             serverPaging: true,
             pageSize: 50
         },

        dataSource = new kendo.data.DataSource({
    //        data: [

    ////{ name: "Xyz", dueDate: '04/04/1990' },

    ////{ name: "Jane Doe", dueDate: '04/27/1988' },
   
    //        ],
    //        sort: { field: "dueDate", dir: "asc" }, //Apply sorting by dob field
    //        schema: {

    //            model: {
    //                fields: {

    //                    dueDate: { type: 'date' }, //Make sure you define a build with correct data type

    //                    name: { type: 'string' }

    //                }

    //            }

    //        }
            pageSize: 50
        }),
        //try to merge dataSources

      
   
        dataSource1 = new kendo.data.DataSource({
            pageSize: 50
        }),
    //      data1 = dataSource.data(); //First data source data
    ////alert(data1 + "data1")
    //var data2 = dataSource1.data(); //Second data source data
    ////alert(data2 + "data2")
    ////concat two array data by converting kendo model to actual json

    //var mergedData = data1.toJSON().concat(data2.toJSON());
    //alert(mergedData + "mergedData")
    //var newDataSource = new kendo.data.DataSource({

    //    data: mergedData,

    //    sort: { field: 'dueDate', dir: 'asc' },

    //    schema: {

    //        model: {

    //            fields: {

    //                dueDate: { type: 'date' },

    //                name: { type: 'string' },

    //            }

    //        }

    //    }

    //});
    //alert(newDataSource + "newDataSource")
    //newDataSource.fetch(function () {
    //    alert(newDataSource.total() + "newDataSource.total()");
    //    var data = newDataSource.view();

    //    console.log(data[0].dueDate);

    //});
        dataSource2 = new kendo.data.DataSource({
            pageSize: 50
        }),
        dataSource3 = new kendo.data.DataSource({
            pageSize: 50
        }),
        dataSource4 = new kendo.data.DataSource({
            pageSize: 50
        }),
        dataSource5 = new kendo.data.DataSource({
            pageSize: 50
        }),
         dataSource10 = new kendo.data.DataSource({
             pageSize: 50
         }),

        homeModel = kendo.observable({
            addRecord: null,
            dataSource: dataSource,
            dataSource1: dataSource1,
            dataSource2: dataSource2,
            dataSource3: dataSource3,
            dataSource4: dataSource4,
            dataSource5: dataSource5,
            dataSource10:dataSource10,
            _dataSourceOptions: dataSourceOptions,
            _dataSourceOptions1: dataSourceOptions1,
            _dataSourceOptions2: dataSourceOptions2,
            _dataSourceOptions3: dataSourceOptions3,
            _dataSourceOptions4: dataSourceOptions4,
            _dataSourceOptions5: dataSourceOptions5,
            _jsdoOptions: jsdoOptions,
            _jsdoOptions1: jsdoOptions1,
            _jsdoOptions2: jsdoOptions2,
            _jsdoOptions3: jsdoOptions3,
            _jsdoOptions4: jsdoOptions4,
            _jsdoOptions5: jsdoOptions5,

            searchChange: function (e) {
                var searchVal = e.target.value,
                    searchFilter;

                if (searchVal) {
                    searchFilter = {
                        //here you decide according to what it'll be filtering- according to 'name' 'subject'....
                        field: 'name',
                        operator: 'contains',
                        value: searchVal
                    };
                }
                fetchFilteredData(homeModel.get('paramFilter'), searchFilter);
            },
            currentItem: null,

            itemClick: function (e) {
                var dataItem = e.dataItem || homeModel.originalItem;
                //alert(e.dataItem.uid)
                app.mobileApp.navigate('#components/worksPlans1/trainingTaskSchoolDetails.html?uid=' + e.dataItem.uid);
            },
            itemClick1: function (e) {
                var dataItem = e.dataItem || homeModel.originalItem;
                app.mobileApp.navigate('#components/worksPlans1/directiveTaskSchoolDetails.html?uid=' + e.dataItem.uid);
            },
            itemClick2: function (e) {
                var dataItem = e.dataItem || homeModel.originalItem;
                //alert(e.dataItem.uid)
                app.mobileApp.navigate('#components/worksPlans1/exerciseTaskSchoolDetails.html?uid=' + e.dataItem.uid);
            },
            itemClick3: function (e) {
                var dataItem = e.dataItem || homeModel.originalItem;
                app.mobileApp.navigate('#components/worksPlans1/trainingTaskKGartenDetails.html?uid=' + e.dataItem.uid);
            },
            itemClick4: function (e) {
                var dataItem = e.dataItem || homeModel.originalItem;
                app.mobileApp.navigate('#components/worksPlans1/directiveTaskKGartenDetails.html?uid=' + e.dataItem.uid);
            },
            itemClick5: function (e) {
                var dataItem = e.dataItem || homeModel.originalItem;
                app.mobileApp.navigate('#components/worksPlans1/exerciseTaskKGartenDetails.html?uid=' + e.dataItem.uid);
            },
            viewNameSub: function (subject1, num) {
                //SUBSTRING:
                //keeps here aar- it works!!
                //  var newname = "`aarr1'".substring(1, 4)

                var aarr6 = {};
                if (num == 0) {
                    aarr6 = aarr;
                }
                if (num == 1) {
                    aarr6 = aarr1;
                }
                if (num == 2) {
                    aarr6 = aarr2;
                }
                if (num == 3) {
                    aarr6 = aarr3;
                }
                if (num == 4) {
                    aarr6 = aarr4;
                }
                if (num == 5) {
                    aarr6 = aarr5;
                }
                for (var i in aarr6) {
                    if (subject1 == i)
                        return (aarr6[i])
                }
            },
            //viewNameSub1: function (subject1) {
            //    for (var i in aarr1) {
            //        if (subject1 == i)
            //            return (aarr1[i])
            //    }
            //},
            detailsShow: function (e) {
                var item = e.view.params.item;
                             //dataSource;
                //dataSource = homeModel.get("dataSource");
                //dataSource = homeModel.get("dataSource1");

                alert(e.view.params.item)

                //var itemModel = dataSource.getByUid(item);

                //dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                //var jsdoOptions = homeModel.get('_jsdoOptions1'),
                //    jsdo = new progress.data.JSDO(jsdoOptions),
                //    dataSourceOptions = homeModel.get('_dataSourceOptions1'),
                //    dataSource;

                //dataSourceOptions.transport.jsdo = jsdo;
                //dataSource = new kendo.data.DataSource(dataSourceOptions);

                //dataSource.fetch(function () {
                //    alert(dataSource.total());
                //});
                homeModel.set('currentItem', item);
                //alert(homeModel.currentItem.description)
            },
            setCurrentItemByUid: function (uid) {
                var item = uid,
                    dataSource = homeModel.get('dataSource'),
                    itemModel = dataSource.getByUid(item);

                if (!itemModel.name) {
                    itemModel.name = String.fromCharCode(160);
                }

                homeModel.set('originalItem', itemModel);
                homeModel.set('currentItem',
                homeModel.fixHierarchicalData(itemModel));

                return itemModel;
            },
            fixHierarchicalData: function (data) {
                var result = {},
                    layout = {};

                $.extend(true, result, data);

                (function removeNulls(obj) {
                    var i, name,
                        names = Object.getOwnPropertyNames(obj);

                    for (i = 0; i < names.length; i++) {
                        name = names[i];

                        if (obj[name] === null) {
                            delete obj[name];
                        } else if ($.type(obj[name]) === 'object') {
                            removeNulls(obj[name]);
                        }
                    }
                })(result);
                (function fix(source, layout) {
                    var i, j, name, srcObj, ltObj, type,
                        names = Object.getOwnPropertyNames(layout);

                    for (i = 0; i < names.length; i++) {
                        name = names[i];
                        srcObj = source[name];
                        ltObj = layout[name];
                        type = $.type(srcObj);

                        if (type === 'undefined' || type === 'null') {
                            source[name] = ltObj;
                        } else {
                            if (srcObj.length > 0) {
                                for (j = 0; j < srcObj.length; j++) {
                                    fix(srcObj[j], ltObj[0]);
                                }
                            } else {
                                fix(srcObj, ltObj);
                            }
                        }
                    }
                })(result, layout);

                return result;
            },
            
    parent.set('homeModel', homeModel);

    parent.set('onShow', function (e) {

        var param = e.view.params.filter ? JSON.parse(e.view.params.filter) : null,
                       isListmenu = false,
                       backbutton = e.view.element && e.view.element.find('header [data-role="navbar"] .backButtonWrapper');

        if (param || isListmenu) {
            backbutton.show();
            backbutton.css('visibility', 'visible');
        } else {
            if (e.view.element.find('header [data-role="navbar"] [data-role="button"]').length) {
                backbutton.hide();
            } else {
                backbutton.css('visibility', 'hidden');
            }
        }

        try {
            //i retreive few charts- for each one i need to define dataSourceOption.. etc..
            dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                var jsdoOptions = homeModel.get('_jsdoOptions'),
                    jsdo = new progress.data.JSDO(jsdoOptions),
                    dataSourceOptions = homeModel.get('_dataSourceOptions'),
                    dataSource;
                dataSourceOptions.transport.jsdo = jsdo;
                dataSource = new kendo.data.DataSource(dataSourceOptions);

                //list of status
                var statusArr = jsdo.getPicklist_status().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)
                for (var i = 0; i < statusArr.length; i++) {
                    object = statusArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            status[a] = object[property]; //Store the values in a map
                        }
                    }
                }
                //list of subject

                var subjectArr = jsdo.getPicklist_subject().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)
              
                for (var i = 0; i < subjectArr.length; i++) {
                    object = subjectArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            aarr[a] = object[property]; //Store the values in a map
                           
                        }
                    }
                }

                dataSource.sort({ field: "dueDate", dir: "asc" });
                homeModel.set('dataSource', dataSource);
                //sessionStorage.setItem("subjectArray", JSON.stringify(subjectArr));
                fetchFilteredData(param);

            });

            dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                var jsdoOptions1 = homeModel.get('_jsdoOptions1'),
                    jsdo1 = new progress.data.JSDO(jsdoOptions1),
                    dataSourceOptions1 = homeModel.get('_dataSourceOptions1'),
                    dataSource1;
                dataSourceOptions1.transport.jsdo = jsdo1;
                dataSource1 = new kendo.data.DataSource(dataSourceOptions1);

                var subjectArr = jsdo1.getPicklist_subject().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)

                for (var i = 0; i < subjectArr.length; i++) {
                    object = subjectArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            aarr1[a] = object[property]; //Store the values in a map

                        }
                    }
                }
                dataSource1.sort({ field: "dueDate", dir: "asc" });
                homeModel.set('dataSource1', dataSource1);
                //fetchFilteredData(param);
            });

            dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                var jsdoOptions2 = homeModel.get('_jsdoOptions2'),
                    jsdo2 = new progress.data.JSDO(jsdoOptions2),
                    dataSourceOptions2 = homeModel.get('_dataSourceOptions2'),
                    dataSource2;
                dataSourceOptions2.transport.jsdo = jsdo2;
                dataSource2 = new kendo.data.DataSource(dataSourceOptions2);

                var subjectArr = jsdo2.getPicklist_type_of_drill().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)

                for (var i = 0; i < subjectArr.length; i++) {
                    object = subjectArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            aarr2[a] = object[property]; //Store the values in a map

                        }
                    }
                }
                dataSource2.sort({ field: "startDate", dir: "asc" });
                homeModel.set('dataSource2', dataSource2);
                //dataSource2.fetch(function () {
                //    //localStorage.setItem("Sum1Neshek", dataSource1.total());
                //    alert(dataSource2.total());
                //});
            });
            dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                var jsdoOptions3 = homeModel.get('_jsdoOptions3'),
                    jsdo3 = new progress.data.JSDO(jsdoOptions3),
                    dataSourceOptions3 = homeModel.get('_dataSourceOptions3'),
                    dataSource3;
                dataSourceOptions3.transport.jsdo = jsdo3;
                dataSource3 = new kendo.data.DataSource(dataSourceOptions3);
                var subjectArr = jsdo3.getPicklist_subject().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)

                for (var i = 0; i < subjectArr.length; i++) {
                    object = subjectArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            aarr3[a] = object[property]; //Store the values in a map

                        }
                    }
                }
                dataSource3.sort({ field: "dueDate", dir: "asc" });
                homeModel.set('dataSource3', dataSource3);
            });
            dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                var jsdoOptions4 = homeModel.get('_jsdoOptions4'),
                    jsdo4 = new progress.data.JSDO(jsdoOptions4),
                    dataSourceOptions4 = homeModel.get('_dataSourceOptions4'),
                    dataSource4;
                dataSourceOptions4.transport.jsdo = jsdo4;
                dataSource4 = new kendo.data.DataSource(dataSourceOptions4);
                var subjectArr = jsdo4.getPicklist_subject().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)

                for (var i = 0; i < subjectArr.length; i++) {
                    object = subjectArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            aarr4[a] = object[property]; //Store the values in a map

                        }
                    }
                }
                dataSource4.sort({ field: "dueDate", dir: "asc" });
                homeModel.set('dataSource4', dataSource4);
            });
            dataProvider.loadCatalogs().then(function _catalogsLoaded() {
                var jsdoOptions5 = homeModel.get('_jsdoOptions5'),
                    jsdo5 = new progress.data.JSDO(jsdoOptions5),
                    dataSourceOptions5 = homeModel.get('_dataSourceOptions5'),
                    dataSource5;
                dataSourceOptions5.transport.jsdo = jsdo5;
                dataSource5 = new kendo.data.DataSource(dataSourceOptions5);
                var subjectArr = jsdo5.getPicklist_type_of_drill().response.picklistData; // here replace "getPicklist_test_picklist" with the value mentioned in the JSDO operations(as the JSDO catalog is previewd,a query for picklist value is generated.)

                for (var i = 0; i < subjectArr.length; i++) {
                    object = subjectArr[i];
                    for (var property in object) {
                        if (property == "id") {
                            a = object[property];
                        }
                        if (property == "name") {
                            aarr5[a] = object[property]; //Store the values in a map

                        }
                    }
                }
                //try to merge- homeModel.set('dataSource5', dataSource5+dataSource3);
                dataSource5.sort({ field: "startDate", dir: "asc" });
                homeModel.set('dataSource5', dataSource5);
            });
           
        } catch (e) {
            alert("problem with loading data")
        }

        //try to merge dataSources

        var data1 = dataSource.data(); //First data source data
        dataSource10 = dataSource.data();
        alert(dataSource10 + "dataSource10")
        dataSource.fetch(function () {
            alert(dataSource.total() + "dataSource.total()");
        });
        //alert(data1+"data1")
        var data2 = dataSource1.data(); //Second data source data
        //alert(data2 + "data2")
        ////concat two array data by converting kendo model to actual json
       

        var mergedData = data1.toJSON().concat(data2.toJSON());

        //alert(mergedData +"mergedData")
        var newDataSource = new kendo.data.DataSource({

            data: mergedData,

            sort: { field: 'dueDate', dir: 'asc' },

            schema: {

                model: {

                    fields: {

                        dueDate: { type: 'date' },

        //                name: { type: 'string' },

                    }

                }

            }

        });
        //alert(newDataSource + "newDataSource")
        //newDataSource.fetch(function () {
        //    alert(newDataSource.total() + "newDataSource.total()");
        //    var data = newDataSource.view();

        //    console.log(data[0].dueDate);

        //});
    });
   
})(app.allWorkPlans);


Posted by Vimalkumar Selvaraj on 24-Aug-2016 07:10

Hi Shira,

I am sorry it's too much code to understand entire stuff with out actual data, but found few things which may be causing issue for you

First thing I noticed is your Datasource Schema mode seems to be incorrect, it should be like this.

dataSourceOptions = {
type: 'jsdo',
transport: {},
schema: {
model: {
fields: {
'dueDate': {
type: 'date',
defaultValue: ''
},
}
}
},
serverFiltering: true,
serverSorting: true,
serverPaging: true,
pageSize: 50
}

Second issue i can sense is, you are populating your DataSources on call back of loadCatalogs() promise, so ideally you can move merging Datasources to separate method and call that method only when both first and second datasources are populated.
Say for an example something below

function mergeDataSources(dataSource1,dataSource2){
dataSource1.fetch(function (){
var data1 = dataSource1.data();
dataSource2.fetch(function(){
var data2 = dataSource2.data();
var mergedData = data1.toJSON().concat(data2.toJSON());
var newDataSource = new kendo.data.DataSource({
data: mergedData,
sort: { field: 'dueDate', dir: 'asc' },
schema: {
model: {
fields: {
dueDate: { type: 'date' },

}
}
}
});
newDataSource.fetch(function () {
var rec = newDataSource.view();
alert(rec[0].dueDate)
});
})
});
}

Hope this helps,

 

Thanks,

Vimal

Posted by Shira Taytelbaom on 24-Aug-2016 08:24
Thanks a lot, for all your help!!
I changed the dataSourceOptions ,so now the dataSourceOptions seems fine.
I don't know what causes the issue now,
But the NewDataSource still seems empty,
Where exactly you think I should call the function mergeDataSources?
in the end of the onShow function??

(And, do I need to loadCatalogs again in the beginning of the mergeDataSource function?
I don't kniw why it's so problamatic.... I want it to work already! :) )

THANKS SO MUCH!
Shira

Posted by Vimalkumar Selvaraj on 24-Aug-2016 12:41

Hi Shira,

It's hard to figure out what goes wrong by looking at such a large code unless I see them with actual data and flow of execution. Could you please raise a support ticket and schedule a call tomorrow  with the help of our support engineer?. I can debug on your machine and try to fix what's goes wrong. From your sample code I can understand you are working on Telerik platform using JSDO  data, but javascript code is not even formatted so unable to figure out actual issue.

Thanks,

Vimal.

Posted by Shira Taytelbaom on 25-Aug-2016 02:58
It works now!!!
Thank you very much!!
It was all correct, the only thing I needed to had was one row...
Thanks SO MUCH!
Shira

Posted by Vimalkumar Selvaraj on 25-Aug-2016 03:01

Hi Shira,

I am glad it worked for you. Please let us know if you need further assistance on this.

Thanks,

Vimal.

Posted by Shira Taytelbaom on 25-Aug-2016 03:06
Thank you! have a great day! :)

This thread is closed