webgui/www/extras/yui/examples/datatable/dt_cellediting_clean.html
2008-03-25 16:13:25 +00:00

108 lines
No EOL
4.4 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-min.js"></script>
<script type="text/javascript" src="../../build/element/element-beta-min.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-beta-min.js"></script>
<script type="text/javascript" src="../../build/datatable/datatable-beta-min.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>";
};
var myColumnDefs = [
{key:"uneditable"},
{key:"address", formatter:this.formatAddress, editor:"textarea"},
{key:"city", editor:"textbox"},
{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>