Created
July 29, 2013 20:09
-
-
Save ryanwjackson/6107335 to your computer and use it in GitHub Desktop.
HandsonTable Custom Render
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var container = $("#edit-metrics-handson-table") | |
var renderResponse = function (instance, td, row, col, prop, value, cellProperties) { | |
if (row == 0 || col == 0) { | |
cellProperties.readOnly = true; | |
} | |
// console.log(arguments) | |
new_args = $.extend(true, [], arguments) | |
if( value != null && value.constructor == Object ) { | |
console.log("here") | |
new_args[5] = arguments[5].value | |
} | |
console.log(new_args) | |
// console.log(this) | |
Handsontable.TextCell.renderer.apply(this, new_args); | |
if( value != null && value.constructor == Object ) { | |
$(td).attr("id", arguments[5].id); | |
} | |
return td; | |
}; | |
$(container).handsontable({ | |
cells: function(row, col, prop) { | |
this.renderer = renderResponse | |
}, | |
afterChange: function (change, source) { | |
console.log(change) | |
console.log(source) | |
if (change != null && change.length > 0) | |
console.log(table.getCell(change[0][0], change[0][1])) | |
} | |
}); | |
var data = [ | |
["", "Kia", "Nissan", "Toyota", "Honda"], | |
[2008, { id: "id1", value: "10"}, 11, 12, 13], | |
[2009, { id: "id2", value: "20"}, 11, 14, 13], | |
[2010, { id: "id2", value: "30"}, 15, 12, 13] | |
]; | |
var table = $(container).data("handsontable") | |
table.loadData(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment