Core Docs | Additional Modules Docs
myTable.loadRows('/some/data');
myTable.loadRows({
url : '/some/data',
//if you return false, the rows are not added
onLoad : function(response){
alert('response');
return true;
}
});
myTable.getHeaderValue = function(){
};
//returns the value of the td node passed to the function
var data = myTable.getCellValue(td);
//returns the value of cell 3 in row 0
var data = myTable.getCellValue(0,3);
myTable.onAfterSort = function(th){
//renumber the first td in each row after sort
var rows = this.body.$('tr');
var x = 1;
rows.forEach(function(v){
v.firstChild.innerHTML = x;
x++;
});
};
myTable.onBeforeSort = function(th){
//do something
};
myTable.onCellClick = function(td){
td.style.backgroundColor = 'pink';
if(td.innerHTML == 'delete'){
$(td.parentNode).remove();
}
};
myTable.onCellMouseOut = function(td){
td.style.backgroundColor = '';
};
myTable.onCellMouseOver = function(td){
td.style.backgroundColor = 'pink';
};
myTable.onColClick = function(column){
//change all the columns to yellow
column.tds.styles({
backgroundColor : 'yellow'
});
if(column.prevColumn){
column.prevColumn.tds.styles({
backgroundColor : ''
});
}
column.values = column.values.map(function(v){
return parseInt(v, 10);
});
alert(column.values.sum());
};
myTable.onHeaderClick = function(th){
th.style.backgroundColor = 'red';
};
myTable.onRowClick = function(tr){
tr.style.backgroundColor = 'red';
};
//removes row 1
mymagicTable.removeRows(1);
//all rows in the array
mymagicTable.removeRows([0,1,5,7]);
//remove all rows in range
mymagicTable.removeRows('1-3');
myTable.sortBy('age');
//or reverse
myTable.sortBy('age', true);
//sort by column 0
myTable.sortBy(0);
//sort by a <th> node DOM reference
myTable.sortBy(th);
myTable.addHeaders(['Blythe', '50','Wed, November 24, 2004','04/12/03','3.9.05', '$6,89']);
myTable.addRows(['Blythe', '50','Wed, November 24, 2004','04/12/03','3.9.05', '$6,89']);
//or
myTable.addRows([
['Julie', 'f', 54, 3456],
['Wendy', 'f', 22, 4562],
['Gina', 'f', 78, 5773],
['Timmy', 'm', 12, 5467],
['Jason', 'm', 45, 3452],
['Tony', 'm', 5, 3456]
]);
myTable.classes.unsortable String The classname for columns you want to set as unsortable, the default is 'unsortable'
myTable.classes.sortable String The classname added to all sortable columns <th>s by sb.magicTable, default is 'sortable'
myTable.classes.sorted_by String The classname added to the <th> being sorted on, default is 'sorted_by'
myTable.classes.force_sort String The className used for forcing sort type
myTable.classes.asc String The className you want used for ascending sorts, if you don't just want the default arrow
myTable.classes.desc String The className you want used for descending sorts, if you don't just want the default arrow
myTable.classes.even String The className used even rows if you want even/odd CSS
myTable.classes.odd String The className used odd rows if you want even/odd CSS
var myTable = new sb.widget.magicTable({
table : '#jimmy',
sortable : 1,
defaultSortedBy : 2,
});
var myTable = new sb.widget.magicTable({
table : '#jimmy',
sortable : 1,
defaultSortedBy : 'age',
});
myTable.setSortTypes(['alpha', 'numeric', 'natural', 'natural', 'usdate', 'usdate', 'alpha']);
var myTable = new sb.widget.magicTable({
table : '#jimmy',
sortable : 1,
defaultSortedBy : 2,
onCellClick : function(td){
td.style.backgroundColor = 'pink';
if(td.innerHTML == 'delete'){
$(td.parentNode).remove();
}
},
onRowClick : function(tr){
tr.style.backgroundColor = 'red';
//alert(tr.innerHTML);
}
});
myTable.sortBy('colName');
//or
var myTable = new sb.widget.magicTable({
table : {
headers : ['name', 'age', 'phone'],
rows : [
['Paul', 31, '228-7445'],
['Matthew', 36, '228-7613'],
['Terry', 29, '228-5731']
]
},
sortable : 1,
onCellClick : function(td){
td.style.backgroundColor = 'pink';
if(td.innerHTML == 'delete'){
$(td.parentNode).remove();
}
},
onRowClick : function(tr){
tr.style.backgroundColor = 'red';
//alert(tr.innerHTML);
}
});
myTable.table.appendTo('body');