Skip to content
Permalink
Browse files

simplify the boolean logic: essentially, if the current row has the s…

…ame selected status as the target row, toggle its selected status, otherwise don't touch it
  • Loading branch information...
yihui committed Jan 18, 2018
1 parent 41ab1af commit b5a735e9b3910798b99e8e4766d2004e7655a94a
Showing with 5 additions and 9 deletions.
  1. +5 −9 inst/htmlwidgets/datatables.js
@@ -822,28 +822,24 @@ HTMLWidgets.widget({
var rowIndex = DT_rows_current.indexOf(i);
if (rowIndex >= 0) {
var row = table.row(rowIndex).nodes().to$();
var flagRowSel = row.hasClass(selClass);
if ((flagSel && !flagRowSel) || (!flagSel && flagRowSel)) {
row.toggleClass(selClass);
}
var flagRowSel = !row.hasClass(selClass);
if (flagSel === flagRowSel) row.toggleClass(selClass);

This comment has been minimized.

Copy link
@shrektan

shrektan Jan 18, 2018

Collaborator

顺眼多了~

}
});
// update selected1
if (flagSel) {
selected1 = unique(selected1.concat(rowsIndex));
} else {
selected1 = selected1.filter(function(index) {
return $.inArray(index, rowsIndex) < 0;
return !inArray(index, rowsIndex);
});
}
} else {
// js starts from 0
shiftSelRowsIndex(lastClickedRow - 1, crtClickedRow - 1).map(function(value) {
var row = table.row(value).nodes().to$();
var flagRowSel = row.hasClass(selClass);
if ((flagSel && !flagRowSel) || (!flagSel && flagRowSel)) {
row.toggleClass(selClass);
}
var flagRowSel = !row.hasClass(selClass);
if (flagSel === flagRowSel) row.toggleClass(selClass);
});
}
e.preventDefault();

0 comments on commit b5a735e

Please sign in to comment.
You can’t perform that action at this time.