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

kend-grid, angularjs, selected item

6 Answers 600 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Enrico
Top achievements
Rank 1
Enrico asked on 20 Oct 2014, 11:25 AM
Hi,

I have a list with and edit button, when clicking on the button I have to open the detail and select the row before opening it. After editing, I want to navigate back to the list and see the latest edited item selected.

This is not working (it use to work in previous implementation angular-kendo):
var dataItem = this.dataItem(this.select());

This works, but I'd not like to not using jquery inside a controller:
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

I'm preserving the last selected item in an outer controller by listening gridOnChange and reset back when gridOnDataBound, something like:

        $scope.lastSelectedDataItem = {};

        $scope.gridOnChange = function (e) {
            var grid = e.sender,
                key = grid.dataSource.transport.options.read.url;
            $scope.lastSelectedDataItem[key] = grid.dataItem(grid.select());
        };

        $scope.gridOnDataBound = function (e) {
            var grid = e.sender,
                key = grid.dataSource.transport.options.read.url,
                view = grid.dataSource.view(),
                i;
            if ($scope.lastSelectedDataItem[key] === undefined) {
                return;
            }
            for (i = 0; i < view.length; i += 1) {
                if (view[i].Id === $scope.lastSelectedDataItem[key].Id) {
                    grid.select(grid.table.find("tr[data-uid='" + view[i].uid + "']"));
                    break;
                }
            }
        };

The selection is working only if I click on the edit icon on the toolbar, not on the text "Edit".

Enrico

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Oct 2014, 07:49 AM
Hello Enrico,

We are not sure what you are asking. Could you please clarify? Getting the selected data item should still work provided there is a selected item. Here is a demo that shows that.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Enrico
Top achievements
Rank 1
answered on 22 Oct 2014, 08:06 AM
Hi,

basically I have a command on each row "Edit". When I press it I'd like the grid to select the row and then navigate into the detail selected.

Right now I'm doing:

$scope.editItem = function (e) {
            e.preventDefault();
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            //var dataItem = this.dataItem(this.select()); // this is not working!
            $scope.$apply(function () {
                $location.path('/activities/' + dataItem.Id);
            });
        };

0
Atanas Korchev
Telerik team
answered on 23 Oct 2014, 07:44 AM
Hello Enrico,

You can pass the data item from the template itself. Here is how: http://dojo.telerik.com/@korchev/amaK

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Enrico
Top achievements
Rank 1
answered on 23 Oct 2014, 08:01 AM
Hi,

since I prefer to configure columns in HTML, is it possible to pass the data item within a standard kendo command? I'll like to preserve the button look and feel with its icon and localized text. Here is my grid:

<div kendo-grid
         k-data-source="gridDataSource"
         k-options="gridOptions"
         k-rebind="gridOptions"
         k-on-data-bound="gridOnDataBound(kendoEvent)"
         k-on-change="gridOnChange(kendoEvent)"
         k-columns='[
            { "field": "Code", "title": "Code" },
            { "field": "Description", "title": "Description" },
            { "field": "SupplierLastCompilationNotificationMessageSendDate", "title": "Compilation send date", "format": "{0:dd/MM/yyyy}" },
            { "field": "SupplierLastCompilationDate", "title": "Last compilation date", "format": "{0:dd/MM/yyyy}" },
            { "command": [
                    { "name": "edit", "text": "Edit", click: editItem },
                    { "name": "delete", "text": "Delete", click: deleteItem }
                ],
                title: " ",
                width: 155
            }
         ]'>
    </div>
0
Atanas Korchev
Telerik team
answered on 23 Oct 2014, 08:08 AM
Hi Enrico,

No this is not possible. The built-in edit command triggers the edit event of the grid. Perhaps you can use it instead. The other options are the code you are currently using or the template from my last example.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Enrico
Top achievements
Rank 1
answered on 23 Oct 2014, 08:17 AM
It's a shame, you should consider to allow this scenario too.

Thanks,
Enrico
Tags
Grid
Asked by
Enrico
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Enrico
Top achievements
Rank 1
Share this question
or