HierarchicalDataSource, get parent fields in parameters from child url function

4 posts, 0 answers
  1. Narjisse
    Narjisse avatar
    2 posts
    Member since:
    Nov 2016

    Posted 30 May 2017 Link to this post

    Hi,

    Is it possible to access in child url function, the parent fields (I want the type to make a condition for the url) ?
    Thank you in advance.  
    Here a part of the source code

    let matieresSource: kendo.data.HierarchicalDataSourceOptions = {
                    transport: {
                        read: {
                            url: (params) => {
                                this.$log.info("params", params);
                                return this.apiEndpoint + "/v1/parcours/" + params.id + "/matieres/edito/tree";
                            },
                            type: "GET",
                            dataType: "json",
                            beforeSend: function (req) {
     
                                let authData = localStorage.getItem('authData');
                                let auth = "Bearer " + JSON.parse(authData).access_token;
     
                                req.setRequestHeader('Authorization', auth);
                            }
                        },
                        parameterMap: (data: kendo.data.DataSourceTransportParameterMapData, type: string) => {
                            // Remove query string in the URL
                            data = null;
     
                            return data;
                        }
                    },
                    schema: {
                        model: {
                            fields: {
                                id: "id",
                                name: "name",
                                type: "type",
                                baseElement: "baseElement",
                                isDirty: "isDirty",
                                hasDirty: "hasDirty",
                                nbChildren: "nbChildren"
                            },
                            hasChildren: (data: any) => {
                                return data.nbChildren > 0 ? true : false;
                            },
                            children: modulesSource
                        }
                    }
                };
     
                let parcoursSource: kendo.data.HierarchicalDataSourceOptions = {
                    transport: {
                        read: {
                            url: (params) => {
                                return this.apiEndpoint + "/v1/parcours/edito/tree";
                            },
                            type: "GET",
                            dataType: "json",
                            beforeSend: function (req) {
     
                                let authData = localStorage.getItem('authData');
                                let auth = "Bearer " + JSON.parse(authData).access_token;
     
                                req.setRequestHeader('Authorization', auth);
                            }
                        },
                        parameterMap: (data: kendo.data.DataSourceTransportParameterMapData, type: string) => {
     
                            return data;
                        }
                    },
                    schema: {
                        model: {
                            fields: {
                                id: "id",
                                idLms: "idLms",
                                name: "name",
                                type: "type",
                                baseElement: "baseElement",
                                isDirty: "isDirty",
                                nbChildren: "nbChildren"
                            },
                            hasChildren: (data: any) => {
                                return data.nbChildren > 0 ? true : false;
                            },
                            children: matieresSource
                        }
                    }
                };
  2. Nencho
    Admin
    Nencho avatar
    1871 posts

    Posted 01 Jun 2017 Link to this post

    Hello Narjisse,

    I am afraid that the requested functionality is not feasible. Could you share a bit more about your scenario, so we could eventually suggest you an alternative implementation for your scenario?

    Regards,
    Nencho
    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.
  3. Narjisse
    Narjisse avatar
    2 posts
    Member since:
    Nov 2016

    Posted 01 Jun 2017 in reply to Nencho Link to this post

    Hello Nencho,

    Thank you for your reply. I solved my problem by modifying the url of the children of a node (with  specific type) during the databound.
    I thought there was a solution already integrated with kendo to change the url of children according to the parent when declaring the dataSource :( 
    Here is the solution I found : 

    /**
     * Fonction événement
     * @param e kenod.ui.TreeViewDataBoundEvent
     */
    private onDataBound(e: kendo.ui.TreeViewDataBoundEvent):void {
     
                let item: IElementNode = e.sender.dataItem(e.node) as IElementNode;
                let data: kendo.data.ObservableArray = null;
     
                if (item !== undefined && item !== null) {
     
                    // Récupération des enfants
                    data = item.children.data();
     
                    // En fonction du type de l'item qu'on "expand", on vérifie ses fils
                    switch (item.type) {
                        case "parcours":
                            this.changeChildrenSource(data);
                            this.expandItemsAndSelectItem("matiere", data);
                            break;
     
                        case "matiere":
                            this.expandItemsAndSelectItem("module", data);
                            break;
                           .....
    }
     
    /**
      * Fonction pour modifier l'url des enfants si besoin
      * @param data
    */
    private changeChildrenSource(data: kendo.data.ObservableArray):void {
     
                if(data) {
                    // On vérifie le type de l'élément actuel pour modifier la source de ses enfants
                    data.forEach((element: IElementNode) => {
     
                        switch (element.type) {
                            case "competence":
                                element.children.options.transport.read.url = (params) => {
                                    return this.apiEndpoint + "/v1/competences/" + element.id + "/evaluations/edito/tree";
                                }
                                break;
                         
                            default:
                                break;
                        
                    });
                }
    }
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I solved my problem by modifying the url of the children of a node during the databound
    I thought there was a solution already integrated with kendo to change the url of children according to the parent when declaring the dataSource
  4. Nencho
    Admin
    Nencho avatar
    1871 posts

    Posted 02 Jun 2017 Link to this post

    Hello Narjisse,

    Thank you for sharing your solution with the community!

    Regards,
    Nencho
    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