Todd Smith![]()
This module includes a Plugin that uses the Gallery-ContextMenu-View to create an easy "right-click"-type menu to use with DataTable.
It includes the capability to define different context menus for the THEAD, TBODY or TFOOT elements of a DataTable.
The plugin fires events that can be listened to that include references to the TR or TD (or TH) Node that the context menu was opened on in addition to the menu selection that was made.
NOTE: This is basically a helper method to assist in making a Gallery-ContextMenu-View contextmenu on a DataTable without having to mess with "delegate", etc ... it does that for you. For more info, see the Gallery-ContextMenu-View page/docs/api.
<script src="http://yui.yahooapis.com/3.8.1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2013.01.16-21-05'
}).use('datatable', 'gallery-datatable-contextmenu', function(Y) {
//
// Create the DataTable
//
var dt = new Y.DataTable({
columns: [ 'rid', 'rtext', 'rnum' ],
data: myData,
sortable: true,
});
dt.render('#tablediv');
//
// Setup a context-menu on the TBODY
//
dt.plug(Y.Plugin.DataTableContextMenu,{
tbodyMenu:{
menuItems: [
{label:"Edit", value:"e" },
{label:"Update", value:"u"},
{label:"Insert Before", value:"i"},
{label:"Insert After", value:"a"},
{label:"Delete Record", value:"d"}
],
after:{
'selectedMenuChange': tdMenuChange
}
},
theadMenu:{
menuItems: [ "Sort A-Z", "Sort Z-A", "Hide" ],
after: {
'selectedMenuChange': thMenuSelect
}
}
});
//
// Listeners for selectedMenuChange events (thMenuSelect similar)
//
function tdMenuChange(e){
// Original clicked TD ... this.get('contextTarget')
// Selected menu item;
// e.newVal.menuItem ... from the "menuItems" ATTR
// e.newVal.menuIndex ... index within the "menuItems" ATTR
};
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info