如何修复“未捕获的TypeError:$ .jqx.pivot不是构造函数”

时间:2019-08-16 07:04:24

标签: javascript pivot jqwidget

我正在使用jqxPiveGrid,但是它不起作用,并且在控制台上显示了问题:Uncaught TypeError:$ .jqx.pivot不是构造函数。 enter image description here 我正在将Visual Studio 2015(ASP.Net MVC)用于网站。

下面是我的代码:

var dataList = new Array();
    dataList= [
      { Style: 'Top', RangeStart: 0, RangeEnd: 10, Day: 1, Value: 0  },
      { Style: 'Top', RangeStart: 0, RangeEnd: 10, Day: 2, Value: 2  },
      { Style: 'Top', RangeStart: 0, RangeEnd: 10, Day: 3, Value: 3  },
      { Style: 'Top', RangeStart: 10.1, RangeEnd: 15, Day: 1, Value: 4  },
      { Style: 'Top', RangeStart: 10.1, RangeEnd: 15, Day: 2, Value: 8  },
      { Style: 'Top', RangeStart: 10.1, RangeEnd: 15, Day: 3, Value: 12  },
      { Style: 'Pants ', RangeStart: 0, RangeEnd: 10, Day: 1, Value: 0  },
      { Style: 'Pants ', RangeStart: 0, RangeEnd: 10, Day: 2, Value: 1  },
      { Style: 'Pants ', RangeStart: 0, RangeEnd: 10, Day: 3, Value: 2  },
      { Style: 'Pants ', RangeStart: 10.1, RangeEnd: 15, Day: 1, Value: 3  },
      { Style: 'Pants ', RangeStart: 10.1, RangeEnd: 15, Day: 2, Value: 5  },
      { Style: 'Pants ', RangeStart: 10.1, RangeEnd: 15, Day: 3, Value: 7  },
    ];

       var source =
            {
                localdata: dataList,
                datatype: "array",
                datafields:
                [
                    { name: 'Style', type: 'string' },
                    { name: 'RangeStart', type: 'number' },
                    { name: 'RangeEnd', type: 'number' },
                    { name: 'Day', type: 'number' },
                    { name: 'Value', type: 'number' },
                ]
            };
            var dataAdapter = new $.jqx.dataAdapter(source);
            // create a pivot adapter from the dataAdapter
            var pivotAdapter = new $.jqx.pivot(
                dataAdapter,
                {
                    pivotValuesOnRows: false,
                    rows: [ { dataField: 'Style' }, {dataField: 'RangeStart'}, {dataField: 'RangeEnd'}],
                    columns: [
                        { dataField: 'Day'},
                        ],
                    values: [
                        { dataField: 'Value', 'function': '', text: '',formatSettings: { decimalPlaces: 2, align: 'right', }},
                    ]
                });
            $('#divPivotGrid').jqxPivotGrid(
                {
                    source: pivotAdapter,
                    treeStyleRows: true,
                    autoResize: false,
                    multipleSelectionEnabled: true
                });    
            setTimeout(_ =>
            {
                var myPivotGridRows = $('#divPivotGrid').jqxPivotGrid('getPivotRows');
                var myPivotGridColumns = $('#divPivotGrid').jqxPivotGrid('getPivotColumns');
                var items = myPivotGridColumns.items;
                var firstItem = items[0];
                var firstItemValueItems = firstItem.valueItems[0];
                var otherHierarchy = firstItem.hierarchy.getHierarchyDepth();

                myPivotGridRows.sortBy(firstItemValueItems, 'desc');
            }, 1500);

但是它在这里完美地工作: https://jseditor.io/?key=pivotgrid-demonstration-of-sortby-method

0 个答案:

没有答案