I'm using smart-table and I need to preselect a specific row.
So after loading my list, I loop into it and set the isSelected
attribute when I reach the item I want to select:
// Preselect a row
for (var i = 0, len = scope.displayCollection.length; i < len; i += 1) {
var person = scope.displayCollection[i];
if (person.firstName === 'Blandine') {
person.isSelected = true;
scope.selected = person;
break;
}
}
It's working fine, but when I want to select another line, the preselected line is not unselected! I have to click on it to manually unselect it and then be able to select another line correctly.
Here is a JSFiddle explaining the issue: http://jsfiddle.net/6pykn5hu/3/
I tried what's proposed there Smart-Table - Select first row displayed (angularjs) but did not manage to have someting working.
Thanks
So I looked through their directive as you can see it calls a function in a parent directive
stTable
. Therow
is bound to a click handler...Which calls thectrl.select()
function fromstTable
this function in turn stores the last selectedrow
. This is your problem because this event does not fire it never sets the last clicked row and thus never looks to remove its class. I rewrote the directive for you so that it would work for what you are trying to achieve but it could pretty easily be improved.Finally I found a solution:
No more
$watch
, but ang-click
on each rows:And I manually unselect all row before selecting the clicked one:
Working JSFiddle: http://jsfiddle.net/6pykn5hu/6/
If someone has a better solution, I am open to other suggestions :)