jQWidgets Forums

jQuery UI Widgets Forums TreeGrid TreeGrid and TypeScript

This topic contains 2 replies, has 2 voices, and was last updated by  liskaj 6 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • TreeGrid and TypeScript #101414

    liskaj
    Participant

    Hello,

    I’m using jqWidgets together with TypeScript (no Angular) however I’m experiencing errors when using TreeGrid. I create instance similar to your sample (https://github.com/jqwidgets/jQWidgets/blob/master/demos/typescript/treegrid/typescript-treegrid.ts):

    this._tree = jqwidgets.createInstance('#types-tree', 'jqxTreeGrid', treeOptions);

    However I’m getting error when subscribing to events or calling any other function from TreeGrid:

    this._tree.addEventHandler('contextmenu', () => {
     ...
    });

    The same approach works fine with other jqx controls (i.e. jqxGrid). I’m using jqWidgets 6.0.5.

    Did I miss something?

    Thank you

    TreeGrid and TypeScript #101415

    Peter Stoev
    Keymaster

    Hi

    The sample actually shows that it successfully calls the expandRow method within the ready callback. This code below shows how to bind to an event:

    /// <reference path="../../../jqwidgets-ts/jqwidgets.d.ts" />
    
    function createTreeGrid(selector) {
        var source =
            {
                dataType: "csv",
                dataFields: [
                    { name: 'EmployeeKey', type: 'number' },
                    { name: 'ParentEmployeeKey', type: 'number' },
                    { name: 'FirstName', type: 'string' },
                    { name: 'LastName', type: 'string' },
                    { name: 'Title', type: 'string' },
                    { name: 'HireDate', type: 'date' },
                    { name: 'BirthDate', type: 'date' },
                    { name: 'Phone', type: 'string' },
                    { name: 'Gender', type: 'string' },
                    { name: 'DepartmentName', type: 'string' }
                ],
                hierarchy:
                {
                    keyDataField: { name: 'EmployeeKey' },
                    parentDataField: { name: 'ParentEmployeeKey' }
                },
                id: 'EmployeeKey',
                url: '../../sampledata/employeesadv.csv'
            };
        var dataAdapter = new $.jqx.dataAdapter(source);
        // Create Tree Grid
        //// initialization options - validated in typescript
        //// jqwidgets.TreeGridOptions has generated TS definition
        var options: jqwidgets.TreeGridOptions = {
            width: 850,
            source: dataAdapter,
            pageable: true,
            columnsResize: true,
            ready: function () {
                // expand row with 'EmployeeKey = 32'
                myTreeGrid.expandRow(32);
                document.querySelector(selector).addEventListener('contextmenu', function (event) {
                    alert("TEST");
                });
    
                myTreeGrid.expandAll();
            },
            columns: [
                { text: 'FirstName', dataField: 'FirstName', minWidth: 100, width: 200 },
                { text: 'LastName', dataField: 'LastName', width: 200 },
                { text: 'Department Name', dataField: 'DepartmentName', width: 150 },
                { text: 'Title', dataField: 'Title', width: 300 },
                { text: 'Birth Date', dataField: 'BirthDate', cellsFormat: 'd', width: 120 },
                { text: 'Hire Date', dataField: 'HireDate', cellsFormat: 'd', width: 120 },
                { text: 'Phone', dataField: 'Phone', cellsFormat: 'd', width: 120 }
            ]
        };
    
        // creates an instance
        var myTreeGrid: jqwidgets.jqxTreeGrid = jqwidgets.createInstance(selector, 'jqxTreeGrid', options);
    }

    Regards,
    Peter

    TreeGrid and TypeScript #101421

    liskaj
    Participant

    Hi Peter,

    thank you for fast response. So I shouldn’t be using addEventHandler method for event subscription, correct? It’s interesting that it works with other controls (i.e. jqxGrid, jqxMenu). While debugging I noticed that host property of tree instance is undefined.

    Thank you,
    -jan

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.