1. #1
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Default Unanswered: mapping problem with the sub array for grid panel

    Unanswered: mapping problem with the sub array for grid panel


    HI... sencha forum members I am having some problem with mapping the json data to my model

    my json data I am receiving is given below

    Code:
    {
        "companydata": [{
            "cmpname": "Kintu Designs Pvt ltd.",
            "cmptitle": "Kintu Designs Pvt ltd.",
            "cmpdesc": "<b>Kintu Designs Pvt ltd.</b>",
            "cmpfax": "8128812153",
            "cmpcontact": "8128812153",
            "cmpwebsite": "www.kintudesigns.com",
            "cmpemail1": "yaryan997@gmail.com",
            "cmpemail2": "yaryan997@gmail.com",
            "cmpcountry": "India",
            "cmpstate": "Gujarat",
            "cmpcity": "Surat",
            "cmpaddress": "Kintu Designs Pvt ltd. Nanpura Surat",
            "departments": [{
                "departname": "Programmers",
                "departdescr": "<b>?Programmers</b>",
                "createdby": 1,
                "createdon": 1200022207000,
                "modifiedon": 1200022207000,
                "modifiedby": 1,
                "id": 1
            }],
            "cmplogo": "calendar.png",
            "cmplogopath": "upload/images/",
            "cmpcreatedby": 1,
            "cmpcreatedon": 1200011900000,
            "cmpmodifiedon": 1200011900000,
            "cmpmodifiedby": 0,
            "id": 1
        }],
        "total": 1,
        "success": true
    }
    my company model is
    Code:
    Ext.define('rms.model.companyModel', {
        extend: 'Ext.data.Model',
        fields : [
                  { name: 'id', type: 'int', useNull: true, mapping: 'id'},
                  { name: 'cmpname', type: 'string', mapping: 'cmpname'},
                  { name: 'cmptitle', type: 'string', mapping: 'cmptitle'},
                  { name: 'cmpdesc', type: 'string', mapping: 'cmpdesc'},
                  { name: 'cmpfax', type: 'string', mapping: 'cmpfax'},
                  { name: 'cmpcontact', type: 'string', mapping: 'cmpcontact'},
                  { name: 'cmpwebsite', type: 'string', mapping: 'cmpwebsite'},
                  { name: 'cmpemail1', type: 'string', mapping: 'cmpemail1'},
                  { name: 'cmpemail2', type: 'string', mapping: 'cmpemail2'},
                  { name: 'cmpcountry', type: 'string', mapping: 'cmpcountry'},
                  { name: 'cmpstate', type: 'string', mapping: 'cmpstate'},
                  { name: 'cmpcity', type: 'string', mapping: 'cmpcity'},
                  { name: 'cmplogo', type: 'string', mapping: 'cmplogo'},
                  { name: 'cmplogopath', type: 'string', mapping: 'cmplogopath'},
                  { name: 'cmpaddress', type: 'string', mapping: 'cmpaddress'},
                  
                  { name: 'departname', type: 'string', mapping: 'departments.departname'},
                  { name: 'departdescr', type: 'string', mapping: 'departments.departdescr'},
              ]
    });
    but still I am not able to show the department name in my grid panel.
    My grid panel is code given below
    Code:
    Ext.define('rms.view.companymgt.companyDetail', {
        extend: 'Ext.grid.Panel',
        alias: 'widget.companydetail',
        id: 'companydetail',
        itemId: 'companydetail',
        store: 'company',
        forceFit: true,
        frame: true,
        initComponent: function() {
            var me = this;
    
    
            Ext.applyIf(me, {
                viewConfig: {
    
    
                },
                columns: [{xtype: 'rownumberer', width: 40},
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'cmptitle',
                        text: 'Company Title'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'departname',
                        text: 'Department Name'
                    }
            });
    
    
            me.callParent(arguments);
        }
    });
    my grid panel shows the company title correctly, but the departname is not shown in the grid panel.

    Please suggest me what's wrong in my above code.


    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

  2. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    115
    Answers
    346
    vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold

      0  

    Default


    Code:
    Ext.define('rms.model.companyModel', {
        extend: 'Ext.data.Model',
        fields : [
            { name: 'id', type: 'int', useNull: true, mapping: 'id'},
            { name: 'cmpname', type: 'string', mapping: 'cmpname'},
            { name: 'cmptitle', type: 'string', mapping: 'cmptitle'},
            { name: 'cmpdesc', type: 'string', mapping: 'cmpdesc'},
            { name: 'cmpfax', type: 'string', mapping: 'cmpfax'},
            { name: 'cmpcontact', type: 'string', mapping: 'cmpcontact'},
            { name: 'cmpwebsite', type: 'string', mapping: 'cmpwebsite'},
            { name: 'cmpemail1', type: 'string', mapping: 'cmpemail1'},
            { name: 'cmpemail2', type: 'string', mapping: 'cmpemail2'},
            { name: 'cmpcountry', type: 'string', mapping: 'cmpcountry'},
            { name: 'cmpstate', type: 'string', mapping: 'cmpstate'},
            { name: 'cmpcity', type: 'string', mapping: 'cmpcity'},
            { name: 'cmplogo', type: 'string', mapping: 'cmplogo'},
            { name: 'cmplogopath', type: 'string', mapping: 'cmplogopath'},
            { name: 'cmpaddress', type: 'string', mapping: 'cmpaddress'},
    
    
            { name: 'departname', type: 'string', mapping: 'departments[0].departname'},
            { name: 'departdescr', type: 'string', mapping: 'departments[0].departdescr'},
        ]
    });

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Default


    HI..

    I am still having that mapping problem with my json response.
    my json response of taskmaindata is
    Code:
    {
        "total": 5,
        "success": true,
        "taskmaindata": [{
            "duration": 3.0,
            "project": {
                "company": {
                    "cmpname": "Kintu Designs pvt ltd",
                    "cmptitle": "Kintu Designs pvt ltd",
                    "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                    "cmpfax": "8128812153",
                    "cmpcontact": "8128812153",
                    "cmpwebsite": "www.kintu.com",
                    "cmpemail1": "yaryan997@gmail.com",
                    "cmpemail2": "yaryan997@gmail.com",
                    "cmpcountry": "India",
                    "cmpstate": "Gujarat",
                    "cmpcity": "Surat",
                    "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                    "cmplogo": "calendar.png",
                    "cmplogopath": "upload/images/",
                    "cmpcreatedby": 1,
                    "cmpcreatedon": 1208078593000,
                    "cmpmodifiedon": 1208078593000,
                    "cmpmodifiedby": 0,
                    "id": 1
                },
                "projectname": "Project 2",
                "projecttitle": "Project 2",
                "projectdesc": "<span style=\"font-weight: bold;\">Project 2 Kintu Designs pvt ltd</span><br>",
                "projectstart": 1208284200000,
                "projectend": 1210876200000,
                "createdby": 1,
                "createdon": 1208078871000,
                "modifiedon": 1208078871000,
                "modifiedby": 1,
                "id": 2
            },
            "startdate": 1327861800000,
            "enddate": 1328121000000,
            "createdby": 1,
            "createdon": 1208078987000,
            "modifiedon": 1208078987000,
            "modifiedby": 1,
            "durationunit": "d",
            "parentid": null,
            "percentdone": 56,
            "taskindex": 0,
            "taskname": "Task 1 2",
            "resources": [{
                "employee": {
                    "username": "",
                    "surname": "Singh",
                    "bank": {
                        "bankname": "ICICI bank",
                        "bankaddress": "ICICI bank nanpura",
                        "id": 1
                    },
                    "designation": {
                        "department": {
                            "company": {
                                "cmpname": "Kintu Designs pvt ltd",
                                "cmptitle": "Kintu Designs pvt ltd",
                                "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                                "cmpfax": "8128812153",
                                "cmpcontact": "8128812153",
                                "cmpwebsite": "www.kintu.com",
                                "cmpemail1": "yaryan997@gmail.com",
                                "cmpemail2": "yaryan997@gmail.com",
                                "cmpcountry": "India",
                                "cmpstate": "Gujarat",
                                "cmpcity": "Surat",
                                "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                                "cmplogo": "calendar.png",
                                "cmplogopath": "upload/images/",
                                "cmpcreatedby": 1,
                                "cmpcreatedon": 1208078593000,
                                "cmpmodifiedon": 1208078593000,
                                "cmpmodifiedby": 0,
                                "id": 1
                            },
                            "departname": "Programmer",
                            "departdescr": "<b>?Programmer</b>",
                            "createdby": 1,
                            "createdon": 1208078617000,
                            "modifiedon": 1208078617000,
                            "modifiedby": 1,
                            "id": 1
                        },
                        "designame": "JAVA Programmer",
                        "desigdescr": "<b>JAVA Programmer</b>?",
                        "createdby": 1,
                        "createdon": 1208078653000,
                        "modifiedon": 1208078653000,
                        "modifiedby": 1,
                        "id": 1
                    },
                    "firstname": "Yogendra",
                    "createdby": 1,
                    "createdon": 1208078726000,
                    "modifiedon": 1208078727000,
                    "modifiedby": 1,
                    "gender": "M",
                    "marital": "U",
                    "nationality": "",
                    "dateofbirth": null,
                    "joindate": null,
                    "contactno": "",
                    "mobileno": "",
                    "email": "",
                    "otheremail": "",
                    "fathername": "",
                    "mothername": "",
                    "accountno": "523223878",
                    "salary": "5000",
                    "address": "",
                    "id": 1,
                    "password": ""
                },
                "name": "Yogendra",
                "id": 3
            }, {
                "employee": {
                    "username": "",
                    "surname": "",
                    "bank": {
                        "bankname": "ICICI bank",
                        "bankaddress": "ICICI bank nanpura",
                        "id": 1
                    },
                    "designation": {
                        "department": {
                            "company": {
                                "cmpname": "Kintu Designs pvt ltd",
                                "cmptitle": "Kintu Designs pvt ltd",
                                "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                                "cmpfax": "8128812153",
                                "cmpcontact": "8128812153",
                                "cmpwebsite": "www.kintu.com",
                                "cmpemail1": "yaryan997@gmail.com",
                                "cmpemail2": "yaryan997@gmail.com",
                                "cmpcountry": "India",
                                "cmpstate": "Gujarat",
                                "cmpcity": "Surat",
                                "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                                "cmplogo": "calendar.png",
                                "cmplogopath": "upload/images/",
                                "cmpcreatedby": 1,
                                "cmpcreatedon": 1208078593000,
                                "cmpmodifiedon": 1208078593000,
                                "cmpmodifiedby": 0,
                                "id": 1
                            },
                            "departname": "Programmer",
                            "departdescr": "<b>?Programmer</b>",
                            "createdby": 1,
                            "createdon": 1208078617000,
                            "modifiedon": 1208078617000,
                            "modifiedby": 1,
                            "id": 1
                        },
                        "designame": "JAVA Programmer",
                        "desigdescr": "<b>JAVA Programmer</b>?",
                        "createdby": 1,
                        "createdon": 1208078653000,
                        "modifiedon": 1208078653000,
                        "modifiedby": 1,
                        "id": 1
                    },
                    "firstname": "Hiren",
                    "createdby": 1,
                    "createdon": 1208078751000,
                    "modifiedon": 1208078751000,
                    "modifiedby": 1,
                    "gender": "M",
                    "marital": "U",
                    "nationality": "",
                    "dateofbirth": null,
                    "joindate": null,
                    "contactno": "",
                    "mobileno": "",
                    "email": "",
                    "otheremail": "",
                    "fathername": "",
                    "mothername": "",
                    "accountno": "523223",
                    "salary": "2000",
                    "address": "",
                    "id": 2,
                    "password": ""
                },
                "name": "Hiren",
                "id": 2
            }],
            "id": 1,
            "priority": 2,
            "depth": 1
        }, {
            "duration": 5.0,
            "project": {
                "company": {
                    "cmpname": "Kintu Designs pvt ltd",
                    "cmptitle": "Kintu Designs pvt ltd",
                    "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                    "cmpfax": "8128812153",
                    "cmpcontact": "8128812153",
                    "cmpwebsite": "www.kintu.com",
                    "cmpemail1": "yaryan997@gmail.com",
                    "cmpemail2": "yaryan997@gmail.com",
                    "cmpcountry": "India",
                    "cmpstate": "Gujarat",
                    "cmpcity": "Surat",
                    "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                    "cmplogo": "calendar.png",
                    "cmplogopath": "upload/images/",
                    "cmpcreatedby": 1,
                    "cmpcreatedon": 1208078593000,
                    "cmpmodifiedon": 1208078593000,
                    "cmpmodifiedby": 0,
                    "id": 1
                },
                "projectname": "Project 2",
                "projecttitle": "Project 2",
                "projectdesc": "<span style=\"font-weight: bold;\">Project 2 Kintu Designs pvt ltd</span><br>",
                "projectstart": 1208284200000,
                "projectend": 1210876200000,
                "createdby": 1,
                "createdon": 1208078871000,
                "modifiedon": 1208078871000,
                "modifiedby": 1,
                "id": 2
            },
            "startdate": 1328121000000,
            "enddate": 1328725800000,
            "createdby": 1,
            "createdon": 1208079056000,
            "modifiedon": 1208079056000,
            "modifiedby": 1,
            "durationunit": "d",
            "parentid": null,
            "percentdone": 60,
            "taskindex": 0,
            "taskname": "Task 2 2",
            "resources": [],
            "id": 2,
            "priority": 0,
            "depth": 1
        }, {
            "duration": 10.0,
            "project": {
                "company": {
                    "cmpname": "Kintu Designs pvt ltd",
                    "cmptitle": "Kintu Designs pvt ltd",
                    "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                    "cmpfax": "8128812153",
                    "cmpcontact": "8128812153",
                    "cmpwebsite": "www.kintu.com",
                    "cmpemail1": "yaryan997@gmail.com",
                    "cmpemail2": "yaryan997@gmail.com",
                    "cmpcountry": "India",
                    "cmpstate": "Gujarat",
                    "cmpcity": "Surat",
                    "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                    "cmplogo": "calendar.png",
                    "cmplogopath": "upload/images/",
                    "cmpcreatedby": 1,
                    "cmpcreatedon": 1208078593000,
                    "cmpmodifiedon": 1208078593000,
                    "cmpmodifiedby": 0,
                    "id": 1
                },
                "projectname": "Project 1",
                "projecttitle": "Project 1",
                "projectdesc": "<b>Project 1 Kintu Designs pvt ltd.</b><br>",
                "projectstart": 1208111400000,
                "projectend": 1210357800000,
                "createdby": 1,
                "createdon": 1208078836000,
                "modifiedon": 1208078836000,
                "modifiedby": 1,
                "id": 1
            },
            "startdate": 1327861800000,
            "enddate": 1328898600000,
            "createdby": 1,
            "createdon": 1208079127000,
            "modifiedon": 1208079127000,
            "modifiedby": 1,
            "durationunit": "d",
            "parentid": null,
            "percentdone": 70,
            "taskindex": 0,
            "taskname": "Task 1 1",
            "resources": [{
                "employee": {
                    "username": "",
                    "surname": "Singh",
                    "bank": {
                        "bankname": "ICICI bank",
                        "bankaddress": "ICICI bank nanpura",
                        "id": 1
                    },
                    "designation": {
                        "department": {
                            "company": {
                                "cmpname": "Kintu Designs pvt ltd",
                                "cmptitle": "Kintu Designs pvt ltd",
                                "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                                "cmpfax": "8128812153",
                                "cmpcontact": "8128812153",
                                "cmpwebsite": "www.kintu.com",
                                "cmpemail1": "yaryan997@gmail.com",
                                "cmpemail2": "yaryan997@gmail.com",
                                "cmpcountry": "India",
                                "cmpstate": "Gujarat",
                                "cmpcity": "Surat",
                                "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                                "cmplogo": "calendar.png",
                                "cmplogopath": "upload/images/",
                                "cmpcreatedby": 1,
                                "cmpcreatedon": 1208078593000,
                                "cmpmodifiedon": 1208078593000,
                                "cmpmodifiedby": 0,
                                "id": 1
                            },
                            "departname": "Programmer",
                            "departdescr": "<b>?Programmer</b>",
                            "createdby": 1,
                            "createdon": 1208078617000,
                            "modifiedon": 1208078617000,
                            "modifiedby": 1,
                            "id": 1
                        },
                        "designame": "JAVA Programmer",
                        "desigdescr": "<b>JAVA Programmer</b>?",
                        "createdby": 1,
                        "createdon": 1208078653000,
                        "modifiedon": 1208078653000,
                        "modifiedby": 1,
                        "id": 1
                    },
                    "firstname": "Yogendra",
                    "createdby": 1,
                    "createdon": 1208078726000,
                    "modifiedon": 1208078727000,
                    "modifiedby": 1,
                    "gender": "M",
                    "marital": "U",
                    "nationality": "",
                    "dateofbirth": null,
                    "joindate": null,
                    "contactno": "",
                    "mobileno": "",
                    "email": "",
                    "otheremail": "",
                    "fathername": "",
                    "mothername": "",
                    "accountno": "523223878",
                    "salary": "5000",
                    "address": "",
                    "id": 1,
                    "password": ""
                },
                "name": "Yogendra",
                "id": 1
            }],
            "id": 3,
            "priority": 2,
            "depth": 1
        }, {
            "duration": 1.0,
            "project": {
                "company": {
                    "cmpname": "Kintu Designs pvt ltd",
                    "cmptitle": "Kintu Designs pvt ltd",
                    "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                    "cmpfax": "8128812153",
                    "cmpcontact": "8128812153",
                    "cmpwebsite": "www.kintu.com",
                    "cmpemail1": "yaryan997@gmail.com",
                    "cmpemail2": "yaryan997@gmail.com",
                    "cmpcountry": "India",
                    "cmpstate": "Gujarat",
                    "cmpcity": "Surat",
                    "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                    "cmplogo": "calendar.png",
                    "cmplogopath": "upload/images/",
                    "cmpcreatedby": 1,
                    "cmpcreatedon": 1208078593000,
                    "cmpmodifiedon": 1208078593000,
                    "cmpmodifiedby": 0,
                    "id": 1
                },
                "projectname": "Project 1",
                "projecttitle": "Project 1",
                "projectdesc": "<b>Project 1 Kintu Designs pvt ltd.</b><br>",
                "projectstart": 1208111400000,
                "projectend": 1210357800000,
                "createdby": 1,
                "createdon": 1208078836000,
                "modifiedon": 1208078836000,
                "modifiedby": 1,
                "id": 1
            },
            "startdate": 1327861800000,
            "enddate": 1327948200000,
            "createdby": 1,
            "createdon": 1208079125000,
            "modifiedon": 1208079125000,
            "modifiedby": 1,
            "durationunit": "d",
            "parentid": null,
            "percentdone": 60,
            "taskindex": 1,
            "taskname": "New Task",
            "resources": [],
            "id": 4,
            "priority": 1,
            "depth": 1
        }, {
            "duration": 14.0,
            "project": {
                "company": {
                    "cmpname": "Kintu Designs pvt ltd",
                    "cmptitle": "Kintu Designs pvt ltd",
                    "cmpdesc": "<b>?D-104 Toral Appartment Nanpura Surat</b>",
                    "cmpfax": "8128812153",
                    "cmpcontact": "8128812153",
                    "cmpwebsite": "www.kintu.com",
                    "cmpemail1": "yaryan997@gmail.com",
                    "cmpemail2": "yaryan997@gmail.com",
                    "cmpcountry": "India",
                    "cmpstate": "Gujarat",
                    "cmpcity": "Surat",
                    "cmpaddress": "D-104 Toral Appartment Nanpura Surat",
                    "cmplogo": "calendar.png",
                    "cmplogopath": "upload/images/",
                    "cmpcreatedby": 1,
                    "cmpcreatedon": 1208078593000,
                    "cmpmodifiedon": 1208078593000,
                    "cmpmodifiedby": 0,
                    "id": 1
                },
                "projectname": "Project 1",
                "projecttitle": "Project 1",
                "projectdesc": "<b>Project 1 Kintu Designs pvt ltd.</b><br>",
                "projectstart": 1208111400000,
                "projectend": 1210357800000,
                "createdby": 1,
                "createdon": 1208078836000,
                "modifiedon": 1208078836000,
                "modifiedby": 1,
                "id": 1
            },
            "startdate": 1328898600000,
            "enddate": 1330626600000,
            "createdby": 1,
            "createdon": 1208079155000,
            "modifiedon": 1208079155000,
            "modifiedby": 1,
            "durationunit": "d",
            "parentid": null,
            "percentdone": 60,
            "taskindex": 1,
            "taskname": "Task 1 2",
            "resources": [],
            "id": 5,
            "priority": 2,
            "depth": 1
        }]
        }
    and this is my taskmainModel class
    Code:
    Ext.define('rms.model.taskmainModel', {
        extend : 'Ext.data.Model',
    
    
        fields : [ 
                   { name : 'id', type : 'int' }, 
                   { name : 'taskname', type: 'string'},
                   { name : 'priority', defaultValue : 1},
                   { name : 'percentdone' },
                   { name : 'projectname', mapping: 'project.projectname'},
                   { name : 'resourceid', mappping: 'resources.name'},
                   { name : 'resourcename', mappping: 'resources.name'},
                   { name : 'firstname', mappping: 'resources.employee.firstname'},
                   { name : 'cmpname', mapping: 'project.company.cmpname'}
                 ]
    });
    but still I am not able to get the value of resourceid or firstname.

    When I see my JSON I am getting everything that I want to display, but still no values get printed with above model mapping.

    Please suggest me How can I get the resourceid , resourcename, firstname etc from my JSON response.


    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

  4. #4
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    115
    Answers
    346
    vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold

      0  

    Default


    From your json data, 'resources' is an array, so which array item would you like to use? The relation between 'taskmaindata' and 'resources' is one-to-many.

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Default


    @vietits

    I want to use resources array to display the name of the resouce assign to the task. And again there is a one-to-many relationship between the taskmaindata and resource, but to server side.

    From model side I am not able to set the one-to-many relationship between taskmaindata and the resource.

    below is my resourceModel and the taskmainModel I had already added to my previous post.

    Code:
    Ext.define('rms.model.resourceModel',{
        extend: 'Ext.data.Model',
    
    
        fields : [ 
                   { name : 'Id', type : 'int', useNull : true, mapping : 'id' },
                   { name : 'Name', mapping : 'name' }
                 ]
    });
    please suggest me , how can I display the resource name from the json data I am receiving as the response.


    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

  6. #6
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Default


    hi.. vietis

    I solved that problem as per your suggestion and change my model to
    Code:
    Ext.define('rms.model.taskmainModel', {
        extend : 'Ext.data.Model',
    
    
        fields : [ 
                   { name : 'id', type : 'int' }, 
                   { name : 'taskname', type: 'string'},
                   { name : 'priority', defaultValue : 1},
                   { name : 'percentdone' },
                   
                   { name : 'projectname', mapping: 'project.projectname'},
                   { name: 'resourceid', mapping: 'resources[0].name'},
                   { name : 'resourcename', mapping: 'resources[0].name'},
                   { name : 'cmpname', mapping: 'project.company.cmpname'}
                   
                 ]
    
    
    });
    now I am getting the resource name etc. but I am getting only one resource name. If I am having the task with multiple resources still it shows me only one resource in the grid column.

    Consider my resource data as above json response from the server. I am having multiple resource assigned to one task.

    Why my gridPanel only showing the single resource, instead should show the resource name separated by comma sign like

    rishi, yogi, aakash etc. Please suggest me what's wrong with my above code and why my grid panel only shows one resource.

    In my gridPanel two show comma separated resource I trying the below code.
    Code:
    {
                    xtype: 'gridcolumn',
                 dataIndex: 'resourceid',
                 text: 'Resource',
                 field: resourcecombo,
                 renderer: function(value, p, r){
                       return r.data['resourceid']+","+ r.data['resourceid'];
                }
            }
    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

  7. #7
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    115
    Answers
    346
    vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold

      0  

    Default


    Quote Originally Posted by rushi2440 View Post

    I solved that problem as per your suggestion and change my model to
    Code:
    Ext.define('rms.model.taskmainModel', {
        extend : 'Ext.data.Model',
         fields : [ 
                   { name : 'id', type : 'int' }, 
                   { name : 'taskname', type: 'string'},
                   { name : 'priority', defaultValue : 1},
                   { name : 'percentdone' },
                   { name : 'projectname', mapping: 'project.projectname'},
                   { name: 'resourceid', mapping: 'resources[0].name'},
                   { name : 'resourcename', mapping: 'resources[0].name'},
                   { name : 'cmpname', mapping: 'project.company.cmpname'}
                 ]
     });
    now I am getting the resource name etc. but I am getting only one resource name. If I am having the task with multiple resources still it shows me only one resource in the grid column.
    Consider my resource data as above json response from the server. I am having multiple resource assigned to one task.
    Though your data contains multiple resources assigned to one task, but with { name: 'resourceid', mapping: 'resources[0].name'} definition, only name of the first resource is used for resourceid, other resources will be ignored.

    Why my gridPanel only showing the single resource, instead should show the resource name separated by comma sign like rishi, yogi, aakash etc. Please suggest me what's wrong with my above code and why my grid panel only shows one resource.

    In my gridPanel two show comma separated resource I trying the below code.
    Code:
    {
                 xtype: 'gridcolumn',
                 dataIndex: 'resourceid',
                 text: 'Resource',
                 field: resourcecombo,
                 renderer: function(value, p, r){
                       return r.data['resourceid']+","+ r.data['resourceid'];
                }
            }
    You could not get what you want with what you are doing.

    It seems that you want to show a list of tasks with taskname, priority, projectName,... and resources in form of a list of resourceName. If that is true then below is my suggestion for that:

    Model definition
    Code:
    Ext.define('rms.model.taskmainModel', {
        extend : 'Ext.data.Model',
        fields : [ 
            { name : 'id', type : 'int' }, 
            { name : 'taskname', type: 'string'},
            { name : 'priority', defaultValue : 1},
            { name : 'percentdone' },
            { name : 'projectname', mapping: 'project.projectname'},
            { name : 'cmpname', mapping: 'project.company.cmpname'},
            { name : 'resources', type: 'auto'}
        ]
    });
    Grid definition
    Code:
            columns:[{
                ...
            },{
                header: 'ResourcesId',
                dataIndex: 'resources',
                renderer: function(resources){
                    var result = [];
                    resources = resources || [];
                    for (var idx = 0, len = resources.length; idx < len; idx++ ){
                        var value = resources[idx].id;
                        if(value != null){
                            result.push(value);
                        }
                    }
                    return result.join(', ');
                }
            },{
                header: 'Resources name',
                dataIndex: 'resources',
                renderer: function(resources){
                    var result = [];
                    resources = resources || [];
                    for (var idx = 0, len = resources.length; idx < len; idx++ ){
                        var value = resources[idx].name;
                        if(value){
                            result.push(value);
                        }
                    }
                    return result.join(', ');
                }
            }]
            ....
    I wonder why you use such a big data while you only need a few fields of them. There are many extra data. It wastes of loading time and processing time.

  8. #8
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Default


    @ vitetis

    thanks for you reply. The reason I am getting so many data is that I am having relationship server side like one-to-many ext one company has many department. etc.


    So I am getting lots of data as server response. But as of now I used the logic you provided and the solution works perfectly here.


    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

Thread Participants: 1

Tags for this Thread