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

Hierarchical Datasource

1 Answer 76 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris GNB
Top achievements
Rank 1
Chris GNB asked on 25 Jul 2014, 08:38 AM
Hi,
Can anyone help here. I'm new to using Kendo mobile / platform and have 3 content types defined on everlive

Orders - Parent
OrderItems - Child 1:n
OrderSignatures - Child 1:1

I know i have to use the hierarchical DS but how do i define the modal and wire up the datasource.
Any help appreciated.
Cheers Chris


 var ordersModel = (function () {
       
        var orderModel = {
            id: "OrderNumber",
            fields: {
                OrderNumber: { field: 'OrderNumber' },
                CustomerAddress: { field: 'CustomerAddress' },
                CustomerName: { field: 'CustomerName' },
                CustomerNumber: { field: 'CustomerNumber' },
                ProductName: { field: 'ProductName' },
                QuantityOrdered: { field: 'QuantityOrdered' },
                DeliveryDate: { field: 'DeliveryDate', defaultValue: new Date() },
                QuantityDelivered: { field: 'QuantityDelivered', defaultValue: 0 },
                Signature: { field: 'Signature' },
                AcceptedBy: {field: 'AcceptedBy'}
            },
            DeliveryDateFormatted: function () {
                return kendo.toString(new Date(this.DeliveryDate.toString()), 'MM/dd/yyyy')
            }
            
        };//ordermodel
      
        var ordersDataSource = new kendo.data.DataSource({
            type: 'everlive',
            schema: {
                model: orderModel
            },
            transport: {
                typeName: 'Orders'
            },
            change: function (e) {

                if (e.items && e.items.length > 0) {
                    $('#no-orders-span').hide();
                } else {
                    $('#no-orders-span').show();
                }
            }

        }); //datasource
        return {
            orders: ordersDataSource
        };
    }())//ordersModel

1 Answer, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 25 Jul 2014, 03:48 PM
Hi Chris,

Telerik Backend Services have a dedicated way for retrieving the related items - the Expand for Relations functionality. There is also a way to create a hierarchical data source using the Everlive JS SDK.

Here are the relevant resources from the documentation:
The Kendo UI team has a dedicated sample about binding a mobile list view to a hierarchical data source. It can be reached here.

In addition, it may be beneficial to consider the query patterns of your app in advance and if needed, re-design the data schema of your app. Below you can find some details about this.

Telerik Backend Services offer a NoSQL, document-based data store. In NoSQL databases it is generally better to have the related items embedded into the parent document, since getting related items is more difficult (it requires more requests to the DB). When the items are embedded whenever you get the main item you can choose if you also want to get the embedded items or not (using a projection operation from the JS SDK). This is a kind of de-normalization that is often recommended for non-relational data storages.

For instance, if you are going to retrieve the Orders always with their signature, the signature seems like the perfect candidate for embedding. Same applies for the OrderItems - they could also be embedded into the parent Order. There might be some variations on this depending on your requirements, the way you are going to show the information to the users, etc.

Surely, embedding items is not always possible. For example, when a single item is related to more than one other items. The difficult part is retrieving the related items, since you cannot do JOINs. For those scenarios Telerik Backend Services provide Relations and Expand pieces of functionality. Please, note that they are not a replacement of JOIN queries and can also impose some limitations.

Please, let us know if further questions arise.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Chris GNB
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Share this question
or