简体   繁体   English

ag-grid中没有填充函数?

[英]ag-grid is not populating inside a function?

I'm new in using agGrid forgive me if you find something silly. 如果您发现一些愚蠢的东西,那么使用agGrid的人是我的新手。 So before this I was using Kendo Grid on angularjs but we thought to switch to some other grid so we are trying agGrid right now. 因此,在此之前,我在angularjs上使用Kendo Grid,但是我们考虑切换到其他网格,因此我们现在尝试使用agGrid。

Below is the a sample of aggrid which is working fine and everything works. 以下是aggrid的示例,该示例工作正常,一切正常。 But, When i move my grid options inside a function which will be getting called on button click I'm getting WARNING - grid options for ag-Grid not found. 但是,当我在将要在按钮上调用的函数中移动网格选项时,我会收到警告-未找到用于ag-Grid的网格选项。 Please ensure the attribute ag-grid points to a valid object on the scope. 请确保属性ag-grid指向合并范围内的有效对象。

I'm not able to understand what is the problem because inside this function kendo grid options are working fine and kendo grid is getting populated but I'm not sure what i'm doing wrong with the agGrid. 我无法理解问题所在,因为在此功能中,kendo网格选项运行正常,并且已填充kendo网格,但是我不确定agGrid在做什么。

Kindly help me. 请帮助我。

function abc($rootScope,$scope, $state, $stateParams, $timeout, Upload, baseURL, $cookieStore, $log, errorCheckFactory) {
    var columnDefs = [
        {headerName: "Make", field: "make"},
        {headerName: "Model", field: "model"},
        {headerName: "Price", field: "price"}
    ];

    var rowData = [
        {make: "Toyota", model: "Celica", price: 35000},
        {make: "Ford", model: "Mondeo", price: 32000},
        {make: "Porsche", model: "Boxter", price: 72000}
    ];

    $scope.gridOptions2 = {
        columnDefs: columnDefs,
        rowData: rowData,
        enableFilter: true,
        enableColResize: true,
        enableSorting: true,
        groupHeaders: true,
        rowHeight: 22,
        //onModelUpdated: onModelUpdated,
        suppressRowClickSelection: true

    };

} }

If the grid does not foud your gridOptions that surely means you have a typo in your html template 如果网格不适合您的gridOptions,那肯定意味着您的html模板中有错字

Check your hml template it must have 检查您的HML模板必须具有

ag-grid="gridOptions2"

Note : if you use a controller with the controllerAs way, you have to bind variables on this and not on $scope. 注意:如果您使用带controllerAs的控制器,则必须在此绑定变量,而不是$ scope。

If it's not this add, your html and your route/state/whatever definition of the navigation. 如果不是这个添加项,则说明您的html和导航的路线/状态/其他定义。

This is angular-grid binding issue. 这是角度网格绑定问题。 check your scope variable gridOptions. 检查您的范围变量gridOptions。

grid options function: 网格选项功能:

var columnDefs = [
  {displayName: "Make", field: "make"},
  {displayName: "Model", field: "model"},
  {displayName: "Price", field: "price"},
  {displayName: "Price2 ", field: "price2"},
  {displayName: "Test 4", field: "test4"},
  {displayName: "Test 5", field: "test5"},
  {displayName: "Test 6", field: "test6"},
];

var rowData = [
  {make: "Toyota Toyota Toyota Toyota Toyota", model: "Celica", price: 35000, price2: 145, "Test 4": "Test 4", "Test 5": "Test 5", "Test 6": "Test 6"},
  {make: "Acura", model: "Celica", price: 35000, price2: 145, "Test 4": "Test 4", "Test 5": "Test 5", "Test 6": "Test 6"}
];

vm.gridOptions = {
  columnDefs: columnDefs,
  rowData: rowData  
};

Working Plnkr: http://plnkr.co/edit/VRnwnXi6fzyaoJJ1YHOx?p=preview 工作的Plnkr: http ://plnkr.co/edit/VRnwnXi6fzyaoJJ1YHOx?p = preview

Correct binding : <div angular-grid="main.gridOptions" class="ag-fresh" style="width: 100%"></div>

Error Plnkr : http://plnkr.co/edit/zb4Vc2lw5VzRzYwsfhL7?p=preview 错误Plnkr: http ://plnkr.co/edit/zb4Vc2lw5VzRzYwsfhL7?p = preview

In-Correct Binding : <div angular-grid="main.gridOptions2" class="ag-fresh" style="width: 100%"></div>

We changed binding from gridOptions to gridOptions2 and it's giving us warning : VM769 angular-grid.js:1 WARNING - grid options for Angular Grid not found. 我们将绑定从gridOptions更改为gridOptions2,并向我们发出警告:VM769 angular-grid.js:1警告-找不到Angular Grid的网格选项。 Please ensure the attribute angular-grid points to a valid object on the scope. 请确保属性angular-grid指向示波器上的有效对象。

I think this should clear doubts. 我认为这应该消除怀疑。

@ranjeet8082 You can Open the Grid At the time of Click a button, you can write "gridOptions" in side the function. @ ranjeet8082您可以在单击按钮时打开网格,可以在函数旁边编写“ gridOptions”。 So you can load Html Also At that Time using ng-if first you can hide the html click only you can load html and then in options also load at the click function so you don't get any error. 因此,您也可以在那时使用ng-if加载HTML,如果您可以先隐藏html click,则只能加载html,然后在options中也加载click函数,这样就不会出现任何错误。 You can check with this plunker. 您可以检查这个矮人。

<div ng-if="vm.gridOptions"  angular-grid="vm.gridOptions" class="ag-fresh" style="width: 100%"></div>

link 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM