简体   繁体   English

AngularJS Typescript网格UI-将功能设置为列值

[英]AngularJS Typescript grid ui - setting function as a column value

I have the following ui grid in my angularJS app" 我的angularJS应用中有以下ui网格”

this.resultGrid = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    enableHorizontalScrollbar: 0,
    enableSorting: true,
    columnDefs: [
        { name: 'Id', field: 'id' },
        { name: 'Name', field: 'name' },
        { name: 'Street', field: 'street' },
        { name: 'Postcode', field: 'postcode' },
        { name: 'City', field: 'city' },
        { name: 'Country', field: 'country' },
        { name: 'In System', field: 'inSys()' }
    ],
    data: [{ city: "Warsaw", country: "Poland", id: "123456789", name: "Company 1", postcode: "00-122", street: "Waszyngtona", inSys: this.inSys(id); }, //compilation error - cannot find name "id"
{ city: "London", country: "UK", id: "987654321", name: "Company 2", street: "Downtown" }]
};

and the function I want to call inside this controller: 以及我想在此控制器内调用的函数:

inSys = (id: string) => {
    if (id== null || id.length == 0)
        return false;

    return this.myService.recordExistsInSys(id);
}

I have not found any example of how to pass a function as a ui-grid column value in typescript. 我还没有找到任何有关如何在打字稿中将函数作为ui-grid列值传递的示例。 Any ideas how to deal with it? 有什么想法如何处理吗?

I had the same problem and for me this worked: 我遇到了同样的问题,对我来说这可行:

this.resultGrid = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    enableHorizontalScrollbar: 0,
    enableSorting: true,
    context: {
          inSys: (row) => {
              /*do something with row*/
    }
    columnDefs: [
        { name: 'Id', field: 'id' },
        { name: 'Name', field: 'name' },
        { name: 'Street', field: 'street' },
        { name: 'Postcode', field: 'postcode' },
        { name: 'City', field: 'city' },
        { name: 'Country', field: 'country' },
        { name: 'In System', field: 'context.inSys(MODEL_COL_FIELD)' }
    ],
    data: [{ city: "Warsaw", country: "Poland", id: "123456789", name: "Company 1", postcode: "00-122", street: "Waszyngtona", inSys: this.inSys(id); }, //compilation error - cannot find name "id"
{ city: "London", country: "UK", id: "987654321", name: "Company 2", street: "Downtown" }]
};

I didn't try your code but maybe this could help you. 我没有尝试您的代码,但是也许可以帮到您。

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

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