mdDataTable icon indicating copy to clipboard operation
mdDataTable copied to clipboard

table-row-id-key not changing after pagination ajax call

Open Random90 opened this issue 8 years ago • 9 comments

When initializing datatable with these columns: $scope.gridColumns = { 'table-row-id-key': 'id', 'column-keys': [ 'u_avatar', 'u_fullname', 'u_login', 'u_active', 'id' ] }; , table-row-id-key holds my userid used to display an avatar <mdt-custom-cell column-key="u_avatar"> <div avatargrid user="clientScope.getUser(rowId)"</div> </mdt-custom-cell> After ajax call to get another page, rowIds stays the same, and avatar do not display properly

image

Above you can see rowId on first column - it is different from last column, where id is valid. Everything is ok on first page: image

Random90 avatar Dec 23 '16 08:12 Random90

I bumped into this problem, too. I found out that binding to clientScope with rowId did not work properly if the objects bound to the data table did not contain a property with the specified column-key. In your case the objects probably do not have a property called u_avatar?

johannesvaltonen avatar Jan 02 '17 12:01 johannesvaltonen

that is not a case. Every object contains property u_avatar.

Random90 avatar Jan 03 '17 07:01 Random90

Ok, then it's about something else. Either way, I would like this to be fixed, too.

johannesvaltonen avatar Jan 03 '17 08:01 johannesvaltonen

i looked a bit into the source code of mdDataTable: Starting at line 287:

// fill storage with values if set
                function _processData(){
                    if(_.isEmpty($scope.mdtRow)) {
                        return;
                    }
                    //local search/filter
                    if (angular.isUndefined($scope.mdtRowPaginator)) {
                        $scope.$watch('mdtRow', function (mdtRow) {
                            vm.dataStorage.storage = [];

                            _addRawDataToStorage(mdtRow['data']);
                        }, true);
                    }else{
                        //if it's used for 'Ajax pagination'
                    }
                }

Looks like something is missing in else

Random90 avatar Jan 03 '17 08:01 Random90

+1

simonaco avatar Jan 06 '17 07:01 simonaco

#Izanagi13 Please share the code to delete and edit selected code because i am stuck here .

Thanks

SunilVashisht avatar Feb 12 '17 18:02 SunilVashisht

Same problem here. Any solution or Workaround?

amacado avatar Jun 13 '17 12:06 amacado

@Amacado Workaround is very simple. Since rowId stays the same all the time, you can do this:

In your <mdt-custom-cell> add ng-init with function that will create array with initial rowIDs as keys:

$scope.avatarHack = function() {
          angular.forEach($scope.user_icons, function(value,id) {
              //'rowID' is the same as 'id' on first run
              $scope.user_icons_hacked[id] = value;
          });

Whatever happens to your data, you will now have array with rowId keys in proper order. In your paginator callback function, parse received data to array created on init:

var icon_class = []; 
//here I parse received icons to desired format to icon_class array
                    angular.forEach($scope.user_icons_hacked, function(value,id) {
                        if(typeof data.data.item_list[i] !== "undefined")
                            $scope.user_icons_hacked[id] = icon_class[data.data.item_list[i].id];
                        i++;
                    });

data.data.item_list must be a simple array. My mdt-custom-cell:

    <div avatargrid icon="clientScope.getUserClass(rowId)" ng-init="clientScope.avatarHack(rowId)"></div>
<mdt-custom-cell column-key="u_avatar">

This is probably not most elegant workaround, but it is working for me. Sorting and changing rows number is working properly. I hope i made this explanation clear enough for you to understand :)

Random90 avatar Jun 13 '17 12:06 Random90

@Random90 Can you please explain me in detail I got stuck here for long time.

vigneswaranp avatar May 21 '18 13:05 vigneswaranp