This is a migrated thread and some comments may be shown as answers.

Accessing dataItem from outside dataSource function

2 Answers 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 May 2016, 04:27 PM

I have an AngularJS page, and have a populated dataItem. No problem. Now, I would like to populate a dropdown with one of the columns. I can't quite figure out how to do this. Here is my current code. I have hardcoded the dropdown values but would like to populate it instead from the "ticker" column in the dataItem instead. I think this should be super-easy, right?

 

$scope.positionGridOptions = function(dataItem) {
 
    return {
        dataSource: {
            type: "xml",
            transport: {
                read: function(options) {
                    $.ajax({
                        url: "http://fraitcf1vd2607.de.db.com:2701/WS_GetPositionsV3?startDate=" + dataItem.filterStart + "&endDate=" + dataItem.filterEnd + "&fiId=" + dataItem.swapId + "&maxRows=1000",
                        dataType: "xml",
                        success: function(result) {
                            options.success(result);
                        },
                        error: function(result) {
                            options.error(result);
                        }
                    });
                }
            },
            schema: {
                type: "xml",
                data: "/root/row",
                model: {
                    fields: {
                        ticker: {field: "@ticker", type: "string" },
                        longShort: {field: "@longShort", type: "string" },
                        legId: {field: "@legId", type: "number" },
                        instrId: {field: "@instrId", type: "number" },
                        qty: {field: "@qty", type: "number" },
                        thisDay: {field: "@thisDay", type: "string" }
                    }
                }
            },
            serverPaging: false,
            serverSorting: false,
            serverFiltering: false,
            pageSize: 20
        },
        sortable: {
            mode: "multiple",
            allowUnsort: true
        },
        height: 200,
        scrollable: false,
        sortable: true,
        groupable: true,
        pageable: { buttonCount: 4 },
        filterable: {
            extra: false,
            operators: {
                string: {
                    startswith: "Starts with",
                    eq: "Is equal to",
                    neq: "Is not equal to"
                }
            }
        },
        columns: [
            {field: "ticker", title: "Ticker", width: "50px", filterable: {ui: $scope.ticker3Filter} },
            {field: "longShort", title: "Long/Short", width: "50px", filterable: false},
            {field: "legId", title: "Leg ID",  width: "50px", filterable: false},
            {field: "instrId", title: "Instr ID", width: "50px", filterable: false},
            {field: "qty", title: "Quantity", width: "50px", filterable: false},
            {field: "thisDay", title: "Day", width: "50px", filterable: false}
            ]
        };
    };
     
    // How to get the ticker element for each row in dataItem?
    $scope.ticker3Filter = function(element) {
        element.kendoDropDownList({
        optionLabel: "--Select Value--",
        dataSource: ["ABC.AX","AGL.AX","AHD.AX","AHE.AX"]
     });
    }      

2 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 10 May 2016, 04:40 PM
Actually, a slight clarification. I want to get the ticker column which is in the result set, inside the scope of the positionGridOptions function.
0
Mark
Top achievements
Rank 1
answered on 11 May 2016, 12:11 PM

Never mind. I figured it out. I went back out the server and got the filters:

$scope.ticker4Filter = function(element) {
    element.kendoDropDownList({
    dataTextField: "ticker",
    dataValueField: "field",
    dataSource: new kendo.data.DataSource({
        type: "xml",
        transport: {
            read: function(options) {
                $.ajax({
                    url: "http://fraitcf1vd2607.de.db.com:2701/WS_GetFiltersV3?startDate=" + $scope.filterStart + "&endDate=" + $scope.filterEnd + "&fiId=" + $scope.swapId + "&maxRows=100",
                    dataType: "xml",
                    success: function(result) {
                        options.success(result);
                    },
                    error: function(result) {
                        options.error(result);
                    }
                });
            }
        },
        schema: {
            type: "xml",
            data: "/root/row",
            model: {
                fields: {
                    ticker: {field: "@ticker" }
                }
            }
        }
    }),
    optionLabel: "--Select Value--"
});

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Share this question
or