Skip to content

Commit

Permalink
selected data array and rowSelectionChanged event added
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli Folkerd committed Dec 26, 2016
1 parent 5d10691 commit f481376
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
3 changes: 3 additions & 0 deletions examples.html
Expand Up @@ -118,6 +118,9 @@
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross", sorter:"boolean"},
],
rowSelectionChanged:function(data, rows){
console.log("sel", data.length, data, rows);
},
// rowClick:function(e, id, data, row){
// alert("Row " + id + " Clicked!!!!")
// },
Expand Down
53 changes: 50 additions & 3 deletions tabulator.js
Expand Up @@ -38,6 +38,8 @@
data:[],//array to hold data for table
activeData:[],//array to hold data that is active in the DOM

selectedRows:[], //array to hold currently selected rows

firstRender:true, //layout table widths correctly on first render
mouseDrag:false, //mouse drag tracker;
mouseDragWidth:false, //starting width of colum on mouse drag
Expand Down Expand Up @@ -164,6 +166,7 @@
rowContext:function(){},
rowMoved:function(){},
rowUpdated:function(){},
rowSelectionChanged:function(){},

cellEdited:function(){},

Expand Down Expand Up @@ -2862,7 +2865,7 @@
if(newWidth < minWidth){
col.css({"min-width":newWidth});
}
col.css({width:newWidth});
col.css({width:newWidth});

}

Expand Down Expand Up @@ -2983,12 +2986,56 @@

//select row
selectRow:function(row){
row.addClass("tabulator-selected");
var self = this;

var row = isNaN(row) ? row : $(".tabulator-row[data-id=" + row + "]", self.element);

if(row.length){
self.selectedRows.push(row);

row.addClass("tabulator-selected");

self._rowSelectionChanged();
}else{
console.error("Tablulator ERROR (row select): No Matching Row Found");
}

},

//deselect row
deselectRow:function(row){
row.removeClass("tabulator-selected");
var self = this;

var row = isNaN(row) ? row : $(".tabulator-row[data-id=" + row + "]", self.element);

if(row.length){

self.selectedRows.forEach(function(element, i){
if(element[0] === row[0]){
self.selectedRows.splice(i, 1);
}
});

row.removeClass("tabulator-selected");

self._rowSelectionChanged();
}else{
console.error("Tablulator ERROR (row select): No Matching Row Found");
}
},

//handle change in row selection count
_rowSelectionChanged:function(){
var self = this;

var data = [];

self.selectedRows.forEach(function(row){
data.push(row.data("data"));
});

self.options.rowSelectionChanged(data, self.selectedRows);

},

////////////////// Table Interaction Handlers //////////////////
Expand Down

0 comments on commit f481376

Please sign in to comment.