AngularJS Smarttable - select event

Is there a way to trigger an event in the selection row in the Smartular Smart table?

This was a subject in another thread, but there is no answer to this question yet.

Unable to select grid item using SmartTable in Angular JS

+5
source share
2 answers

I needed this function to display the panel when at least one row was selected. I initially set the clock, but decided it was too expensive.

I ended up adding a callback inside the stSelectRow directive.

ng.module('smart-table') .directive('stSelectRow', function () { return { restrict: 'A', require: '^stTable', scope: { row: '=stSelectRow', callback: '&stSelected' // ADDED THIS }, link: function (scope, element, attr, ctrl) { var mode = attr.stSelectMode || 'single'; element.bind('click', function ($event) { scope.$apply(function () { ctrl.select(scope.row, mode, $event.shiftKey); scope.callback(); // AND THIS }); }); //***/// } }; }); 

Then I was able to pass the function from my controller to the directive (note: you could pass the selected line back, I didn’t need to)

 tr ng-repeat="row in customerResultsTable" st-select-row="row" st-select-mode="multiple" st-selected="rowSelected()"> 

Reference to this post for reference . Callback function inside the attr directive defined in different attr parameters

+4
source

Here is an easy way to place it on a Smart Table :

 // fired when table rows are selected $scope.$watch('displayedCollection', function(row) { if(!row) return; // get selected row row.filter(function(r) { if (r.isSelected) { console.log(r); } }) }, true); 

related html:

 <table st-table="displayedCollection" st-safe-src="rowCollection" class="select-table table"> 

This github issue was helpful.

0
source

Source: https://habr.com/ru/post/1211492/


All Articles