DataTable Widget
:: Inline Editing
Sample Code
Data:
YAHOO.example.Data.inventory = [ {SKU:"23-23874", Quantity:43, Item:"Helmet", Description:"Red baseball helmet. Size: Large."}, {SKU:"48-38835", Quantity:84, Item:"Football", Description:"Leather football."}, {SKU:"84-84848", Quantity:31, Item:"Goggles", Description:"Light blue swim goggles"}, {SKU:"84-84843", Quantity:56, Item:"Badminton Set", Description:"Set of 2 badminton rackets, net, and 3 birdies."}, {SKU:"84-39321", Quantity:128, Item:"Tennis Balls", Description:"Canister of 3 tennis balls."}, {SKU:"39-48949", Quantity:55, Item:"Snowboard", Description:""}, {SKU:"99-28128", Quantity:77, Item:"Cleats", Description:"Soccer cleats. Size: 10."}, {SKU:"83-48281", Quantity:65, Item:"Volleyball", Description:""}, {SKU:"89-32811", Quantity:67, Item:"Sweatband", Description:"Blue sweatband. Size: Medium."}, {SKU:"28-22847", Quantity:43, Item:"Golf Set", Description:"Set of 9 golf clubs and bag."}, {SKU:"38-38281", Quantity:35, Item:"Basketball Shorts", Description:"Green basketball shorts. Size: Small."}, {SKU:"82-38333", Quantity:288, Item:"Lip balm", Description:"Lip balm. Flavor: Cherry."}, {SKU:"21-38485", Quantity:177, Item:"Ping Pong Ball", Description:""}, {SKU:"83-38285", Quantity:87, Item:"Hockey Puck", Description:"Glow-in-the-dark hockey puck."} ];
CSS:
/* custom css*/ #editing {margin:1em;} #editing table {border-collapse:collapse;} #editing th, #editing td {border:1px solid #000;padding:.25em;} #editing th {background-color:#696969;color:#fff;}/*dark gray*/ #editing .yui-dt-odd {background-color:#eee;} /*light gray*/ #editing .yui-dt-editable.yui-dt-highlight {background-color:#BEDAFF;} /*light blue*/
Markup:
JavaScript:
var myColumnHeaders = [ {key:"SKU"}, {key:"Quantity",editor:"textbox"}, {key:"Item",editor:"textbox"}, {key:"Description",editor:"textarea"} ]; var myColumnSet = new YAHOO.widget.ColumnSet(myColumnHeaders); var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.inventory); myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; myDataSource.responseSchema = { fields: ["SKU","Quantity","Item","Description"] }; var myDataTable = new YAHOO.widget.DataTable("editing", myColumnSet, myDataSource,{caption:"Example: Inline Editing"}); myDataTable.subscribe("cellClickEvent",myDataTable.onEventEditCell); myDataTable.subscribe("cellMouseoverEvent",myDataTable.onEventHighlightCell); myDataTable.subscribe("cellMouseoutEvent",myDataTable.onEventUnhighlightCell); var onCellEdit = function(oArgs) { YAHOO.log("Cell \"" + oArgs.target.id + "\" was updated from \"" + oArgs.oldData + "\" to \"" + oArgs.newData + "\"", "info", this.toString()); } myDataTable.subscribe("cellEditEvent",onCellEdit);