webgui/www/extras/yui/examples/datatable/dt_cellediting_clean.html
Chris Nehren 8fdd413d12 * resizable text areas now use the YUI 2.5.0 code
* add the new YUI release
* document the change in both the changelog and gotcha.txt
2008-02-26 21:27:14 +00:00

138 lines
No EOL
5.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Inline Cell Editing</title>
<style type="text/css">
/*margin and padding on body element
can introduce errors in determining
element position and are not recommended;
we turn them off as a foundation for YUI
CSS treatments. */
body {
margin:0;
padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="../../build/calendar/assets/skins/sam/calendar.css" />
<link rel="stylesheet" type="text/css" href="../../build/datatable/assets/skins/sam/datatable.css" />
<script type="text/javascript" src="../../build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="../../build/calendar/calendar.js"></script>
<script type="text/javascript" src="../../build/element/element-beta.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-beta.js"></script>
<script type="text/javascript" src="../../build/datatable/datatable-beta.js"></script>
<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
.yui-skin-sam .yui-dt-col-address pre { font-family:arial;font-size:100%; } /* Use PRE in first col to preserve linebreaks*/
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">
<h1>Inline Cell Editing</h1>
<div class="exampleIntro">
<p>This example demonstrates basic inline cell editing features, as well as
more complex customizations, such as input validation and click-to-save interactions.</p>
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
<div id="cellediting"></div>
<script type="text/javascript" src="assets/js/data.js"></script>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.InlineCellEditing = new function() {
// Custom formatter for "address" column to preserve line breaks
this.formatAddress = function(elCell, oRecord, oColumn, oData) {
elCell.innerHTML = "<pre class=\"address\">" + oData + "</pre>";
};
// Custom editor for city column to save input on "enter"
this.editCity = function(oEditor, oSelf) {
var elCell = oEditor.cell;
var oRecord = oEditor.record;
var oColumn = oEditor.column;
var elContainer = oEditor.container;
var value = oRecord.getData(oColumn.key);
// Textbox
var elTextbox = elContainer.appendChild(document.createElement("input"));
elTextbox.type = "text";
elTextbox.style.width = (elCell.offsetWidth + 20) + "px";
elTextbox.value = value;
// Set up a listener
YAHOO.util.Event.addListener(elTextbox, "keyup", function(v){
// Save on "enter"
if(v.keyCode === 13) {
oSelf.saveCellEditor();
}
// Update the tracker value
else {
oSelf._oCellEditor.value = elTextbox.value;
}
});
// Select the text
elTextbox.select();
};
var myColumnDefs = [
{key:"uneditable"},
{key:"address", formatter:this.formatAddress, editor:"textarea"},
{key:"city", editor:this.editCity},
{key:"state", editor:"dropdown", editorOptions:{dropdownOptions:YAHOO.example.Data.stateAbbrs}},
{key:"amount", editor:"textbox", editorOptions:{validator:YAHOO.widget.DataTable.validateNumber}},
{key:"active", editor:"radio", editorOptions:{radioOptions:["yes","no","maybe"],disableBtns:true}},
{key:"colors", editor:"checkbox", editorOptions:{checkboxOptions:["red","yellow","blue"]}},
{key:"last_login", formatter:YAHOO.widget.DataTable.formatDate, editor:"date"}
];
this.myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.addresses);
this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
this.myDataSource.responseSchema = {
fields: ["address","city","state","amount","active","colors",{key:"last_login",parser:YAHOO.util.DataSource.parseDate}]
};
this.myDataTable = new YAHOO.widget.DataTable("cellediting", myColumnDefs, this.myDataSource);
// Set up editing flow
this.highlightEditableCell = function(oArgs) {
var elCell = oArgs.target;
if(YAHOO.util.Dom.hasClass(elCell, "yui-dt-editable")) {
this.highlightCell(elCell);
}
};
this.myDataTable.subscribe("cellMouseoverEvent", this.highlightEditableCell);
this.myDataTable.subscribe("cellMouseoutEvent", this.myDataTable.onEventUnhighlightCell);
this.myDataTable.subscribe("cellClickEvent", this.myDataTable.onEventShowCellEditor);
// Hook into custom event to customize save-flow of "radio" editor
this.myDataTable.subscribe("editorUpdateEvent", function(oArgs) {
if(oArgs.editor.column.key === "active") {
this.saveCellEditor();
}
});
this.myDataTable.subscribe("editorBlurEvent", function(oArgs) {
this.cancelCellEditor();
});
};
});
</script>
<!--END SOURCE CODE FOR EXAMPLE =============================== -->
</body>
</html>