lorenzofox3 / Smart-Table

Code source of Smart Table module: a table/grid for Angularjs
http://lorenzofox3.github.io/smart-table-website/
1.8k stars 513 forks source link

Controller as grammar with Issue #522 #788

Closed KabaTheBear closed 7 years ago

KabaTheBear commented 7 years ago

Hello,

i want to use the Smart-Table App with controller as grammar for AngularJS. I got stuck at the point of keep tracking with selected table entries.

Used plunker below to change $scopes into Vm. notation.

http://plnkr.co/edit/TzY3yiKhZiRsAAbq5bm2?p=preview from issue #522 .

The "Selected Rows" on top of the table wont show or dont get any info about selected rows.

Dont know if i made a mistake or maybe a bug in the library. I checked my changes several times.

MrWook commented 7 years ago

Hello @KabaTheBear ,

first of don't use this plunk its outdated. It use SmartTable version 2.0.3. This plugin is at 2.1.8 now.

Second the selection will be saved into the row itself. If you select a row it will be updated with isSelected as a key field inside the array as you can see in the last column with the checkbox.

So if you wanna see the selected row this will help:

<div ng-repeat="ficheiro in vm.rowCollection">
      <span ng-if="ficheiro.isSelected">
         {{ficheiro.id}}
      </span> 
</div>

The feature for st-select-rows-selected wasn't merged into the master repository as you can see in #495 it was closed.

KabaTheBear commented 7 years ago

Hello @MrWook ,

thank you for your reply, gonna keep that in mind!

I solved it by this way:

$scope.$watch('displayedCollection', function (newVal, oldVal) {
        if (newVal === oldVal) return;
        // debugstage for selected Entries
        console.log("selected items: " + newVal.filter(function (item) {
            return item.isSelected;
        }).length);

        //store selected entries in variable
        vm.selectedEntries = newVal.filter(function (item) { return item.isSelected; });

}, true);