data tables are going to need some work yet, but the other stuff seems to be working 100%
166 lines
5.5 KiB
HTML
166 lines
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>Adding and Deleting Rows</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/button/assets/skins/sam/button.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/element/element-beta-min.js"></script>
|
|
<script type="text/javascript" src="../../build/button/button-min.js"></script>
|
|
<script type="text/javascript" src="../../build/dragdrop/dragdrop-min.js"></script>
|
|
<script type="text/javascript" src="../../build/datasource/datasource-min.js"></script>
|
|
<script type="text/javascript" src="../../build/datatable/datatable-min.js"></script>
|
|
|
|
|
|
<!--begin custom header content for this example-->
|
|
<style type="text/css">
|
|
/* custom styles for this example */
|
|
#buttons {margin-bottom: 1em;}
|
|
</style>
|
|
|
|
<!--end custom header content for this example-->
|
|
|
|
</head>
|
|
|
|
<body class=" yui-skin-sam">
|
|
|
|
|
|
<h1>Adding and Deleting Rows</h1>
|
|
|
|
<div class="exampleIntro">
|
|
<p>Adding and deleting rows dynamically.</p>
|
|
|
|
</div>
|
|
|
|
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
|
|
|
|
<div id="buttons">
|
|
<span id="addrow" class="yui-button yui-push-button">
|
|
<span class="first-child">
|
|
<button type="button">Add one row</button>
|
|
</span>
|
|
</span>
|
|
<span id="deleterow" class="yui-button yui-push-button">
|
|
<span class="first-child">
|
|
<button type="button">Delete top row</button>
|
|
</span>
|
|
</span>
|
|
<span id="addrows" class="yui-button yui-push-button">
|
|
<span class="first-child">
|
|
<button type="button">Add 20 rows</button>
|
|
</span>
|
|
</span>
|
|
<span id="deleterows" class="yui-button yui-push-button">
|
|
<span class="first-child">
|
|
<button type="button" name="button5">Delete top 20 rows</button>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div id="basic"></div>
|
|
|
|
<script type="text/javascript" src="assets/js/data.js"></script>
|
|
<script type="text/javascript">
|
|
YAHOO.util.Event.addListener(window, "load", function() {
|
|
YAHOO.example.DynamicData = function() {
|
|
var data = {one:"one",two:"two",three:"three"};
|
|
|
|
var myColumnDefs = [
|
|
{key:"row",resizeable:true,sortable:true},
|
|
{key:"one",resizeable:true},
|
|
{key:"two",resizeable:true},
|
|
{key:"three",resizeable:true}
|
|
];
|
|
|
|
var myDataSource = new YAHOO.util.DataSource([]);
|
|
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
|
|
myDataSource.responseSchema = {
|
|
fields: ["one","two","three"]
|
|
};
|
|
|
|
var myDataTable = new YAHOO.widget.DataTable("basic",
|
|
myColumnDefs, myDataSource, {});
|
|
|
|
var i=1,
|
|
bReverseSorted = false;
|
|
|
|
// Track when Column is reverse-sorted, since new data will come in out of order
|
|
var trackReverseSorts = function(oArg) {
|
|
bReverseSorted = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
|
|
};
|
|
myDataTable.subscribe("columnSortEvent", trackReverseSorts);
|
|
|
|
// Add one row to the bottom
|
|
var btnAddRow = new YAHOO.widget.Button("addrow");
|
|
btnAddRow.on("click", function() {
|
|
// Clear sort when necessary
|
|
if(bReverseSorted) {
|
|
myDataTable.set("sortedBy", null);
|
|
}
|
|
|
|
var record = YAHOO.widget.DataTable._cloneObject(data);
|
|
record.row = i++;
|
|
myDataTable.addRow(record);
|
|
},this,true);
|
|
|
|
// Add 20 rows to the bottom
|
|
var btnAddRows = new YAHOO.widget.Button("addrows");
|
|
btnAddRows.on("click", function(e) {
|
|
// Clear sort when necessary
|
|
if(bReverseSorted) {
|
|
myDataTable.set("sortedBy", null);
|
|
}
|
|
|
|
var myArray = [];
|
|
for(var l=i;i<=l+19;i++) {
|
|
var record = YAHOO.widget.DataTable._cloneObject(data);
|
|
record.row = i;
|
|
myArray.push(record);
|
|
}
|
|
myDataTable.addRows(myArray);
|
|
},this,true);
|
|
|
|
// Delete one row from the top
|
|
var btnDeleteRow = new YAHOO.widget.Button("deleterow");
|
|
btnDeleteRow.on("click", function() {
|
|
if(myDataTable.getRecordSet().getLength() > 0) {
|
|
myDataTable.deleteRow(0);
|
|
}
|
|
},this,true);
|
|
|
|
// Delete 20 row from the top
|
|
var btnDeleteRows = new YAHOO.widget.Button("deleterows");
|
|
btnDeleteRows.on("click", function() {
|
|
var length = myDataTable.getRecordSet().getLength();
|
|
if(length > 0) {
|
|
var count = (length > 19) ? 20 : length;
|
|
myDataTable.deleteRows(0,count);
|
|
}
|
|
},this,true);
|
|
|
|
return {
|
|
oDS: myDataSource,
|
|
oDT: myDataTable
|
|
};
|
|
}();
|
|
});
|
|
</script>
|
|
|
|
<!--END SOURCE CODE FOR EXAMPLE =============================== -->
|
|
|
|
</body>
|
|
</html>
|