Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
600
Primary/Foreign key data types in igTreeGrid
posted

Is it the case that the PrimaryKey and ForeignKey in an igTreeGrid with flat data both have to be numeric?  The tree grid appears not to render if the data type of the columns are string.

  • 17590
    Offline posted in reply to Alistair Wood

    Hello Alistar,

    Thank you for posting in our community.

    What I can suggest is setting the foreignKeyRootValue option of igTreeGrid. option specifies the foreign key value in the data source to treat as the root level once the grid is data bound. Its default value is -1 (which includes the entire data source). If the foreign key field is of a typr string  the foreignKeyRootValue should be set to the exact same string. For example:

     var flatDS = [
            { "employeeID": "0", "PID": "-1", "firstName": "Andrew", "lastName": "Fuller", "reportsTo": "-" },
            { "employeeID": "2", "PID": "-1", "firstName": "Andrew", "lastName": "Muller", "reportsTo": "-" },
     
            { "employeeID": "4", "PID": "0", "firstName": "Janet", "lastName": "Leverling", "reportsTo": "0" },
            { "employeeID": "5", "PID": "0", "firstName": "Laura", "lastName": "Callahan", "reportsTo": "0" },
            { "employeeID": "6", "PID": "0", "firstName": "Margaret", "lastName": "Peacock", "reportsTo": "0" },
            { "employeeID": "7", "PID": "0", "firstName": "Michael", "lastName": "Suyama", "reportsTo": "0" },
            // sub of ID 4
            { "employeeID": "8", "PID": "4", "firstName": "Anne", "lastName": "Dodsworth", "reportsTo": "4" },
            { "employeeID": "9", "PID": "4", "firstName": "Danielle", "lastName": "Davis", "reportsTo": "4" },
            { "employeeID": "10", "PID": "4", "firstName": "Robert", "lastName": "King", "reportsTo": "4" },
            // sub of ID 2
            { "employeeID": "11", "PID": "2", "firstName": "Peter", "lastName": "Lewis", "reportsTo": "2" },
            { "employeeID": "12", "PID": "2", "firstName": "Ryder", "lastName": "Zenaida", "reportsTo": "2" },
            { "employeeID": "13", "PID": "2", "firstName": "Wang", "lastName": "Mercedes", "reportsTo": "2" }
        ];
        $("#treegrid1").igTreeGrid({
            width: "100%",
            dataSource: flatDS, //bound to flat data source,
            autoGenerateColumns: false,
            primaryKey: "employeeID",
            foreignKey: "PID",
            initialExpandDepth: 1,
            foreignKeyRootValue: "-1",
            columns: [
                { headerText: "Employee ID", key: "employeeID", width: "200px", dataType: "string" },
                { headerText: "First Name", key: "firstName", width: "220px", dataType: "string" },
                { headerText: "Last Name", key: "lastName", width: "220px", dataType: "string" },
                { headerText: "Reports To", key: "reportsTo", width: "130px", dataType: "number" }
            ]
        });

    I am attaching a small sample for your reference. Please test it on your side and let me know if you have any additional questions regarding this matter.

    igTreeGridStringPrimaryKey.zip
  • 600
    Verified Answer
    Offline posted

    Oops ... mistakenly posted to igTree rather than igTreeGrid.  Moved the question over there.