Using Angular UI-Grid, how do you access row entity data without using the row selection?

30,167

This post can be useful, https://technpol.wordpress.com/2014/08/23/upgrading-to-ng-grid-3-0-ui-grid/

Basically, you need to set External scope for your grid, so that you can access data.

Share:
30,167
Ted Herrlich
Author by

Ted Herrlich

I am a Senior Software Developer for a small company in Ohio just starting to work a Single-Page App (SPA) using AngularJS and associated technologies. Fun Stuff!

Updated on July 05, 2022

Comments

  • Ted Herrlich
    Ted Herrlich about 2 years

    I am trying to switch from Smart-Table version 1.x to Angular ui-grid (version 3.0), the replacement for ng-grid.
    I like nearly everything about ui-grid, but one thing is driving me crazy. In smart-table, there is a value for dataRow, which is a convenient way of referencing the entity within a table.

    What I was using it for was populating an html template to include field information from the entity, something like ng-click="$parentScope.edit(dataRow.id)" within the html template placed within a grid cell.

    However, in ui-grid, I can't seem to access the entity object without making a formal row or cell selection. Any effort to include it in a cell template results in an object, (row.entity) but I cannot access any of the entity elements, they show up as undefined. Any ideas?

    Furthermore, I have been able to execute a method in an html template, but only ones with no parameters, not one trying to use a parameter from the entity itself.

    Here is my html template that was working with smart-table:

    <a data-toggle="tooltip" data-placement="top" title="View    {{filteredRowCollection}}"   ng-click="$parent.$parent.$parent.$parent.view(dataRow.id)"
       class="glyphicon glyphicon-camera green">
    </a>
    <a data-toggle="tooltip" data-placement="top" title="Edit {{selectionId}}" ng-click="grid.appScope.edit(row.entity.id)"
       class="glyphicon glyphicon-pencil blue">
    </a>
    <a data-toggle="tooltip" data-placement="top" title="Delete {{selectionId}}"  ng-click="$parent.$parent.$parent.$parent.delete(dataRow.id)"
       class="glyphicon glyphicon-trash red">
    </a>
    

    I was trying to use something like this with ui-grid:

    function edit(row){
        . . .
    };
    

    row, at this point is an object, as is row.entity. I expected to be able to use something like row.entity.id, one of the fields, but it is undefined.