AngularJS Typescript grid ui - 将函数设置为列值

时间:2022-04-26 19:44:49

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. Any ideas how to deal with it?

我还没有找到任何如何在typescript中将函数作为ui-grid列值传递的示例。任何想法如何处理它?

1 个解决方案

#1


0  

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.

我没有尝试你的代码,但也许这可以帮助你。

#1


0  

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.

我没有尝试你的代码,但也许这可以帮助你。