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

Grid selection with Angular $scope.$apply()

1 Answer 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Feb 2015, 08:03 PM
I have a simple grid with the click event bound. When the user clicks a row in the grid, it should be highlighted and a detail table included on the page populated based on data from the selected row.

Within the click event of the grid, I populate an array from the selected row's dataitem. The table is populated via ng-repeat acting on the array. In order to force data binding once the array has been prepared, I'm calling $scope.$apply() - but as soon as that happens, the row selection highlight disappears. I want the selected row to remain highlighted.

    $("#gridItemResults").on("click", "tbody", function (e) {
        var grid = $("#gridItemResults").data("kendoGrid");
        var dataItem = grid.dataItem(grid.select());
        var dataJson = dataItem.toJSON();
        $scope.selectedItem.length = 0;

        // populate the selectedItem arrary from the selected row:
        for (var key in dataJson) {
            if (dataJson.hasOwnProperty(key)) {
                $scope.selectedItem.push({ 'key': convertCamelCase(key), 'value': dataJson[key] });
            }
        }

        $scope.$apply(); // update binding

    });

1 Answer, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 11 Feb 2015, 12:57 PM
Never mind, I was refreshing the grid whenever the page layout changed (duh!).
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Share this question
or