var createGridRowContextMenu = function(e, rowIndex, rowData) {
e.preventDefault();
var grid = $(this);/* grid本身 */
var rowContextMenu = this.rowContextMenu;/* grid上的列头菜单对象 */
grid.datagrid('unselectAll').datagrid('selectRow', rowIndex);
if (!rowContextMenu) {
var tmenu = $('').appendTo('body');
var toolbar = grid.datagrid('getToolbar');
var filedHTML = $('');
var span = $('翻页控制');
var spdiv = $('');
for ( var i = 0; i < toolbar.length; i++) {
var btn = $(toolbar[i]).linkbutton('options');
var btnElement = $(toolbar[i]).linkbutton();
var c = $(btnElement).attr("onclick");
$("").html(btn.text).appendTo(tmenu);
//$('').html(btn.text).appendTo(tmenu);
}
spdiv.append('首页');
spdiv.append('上一页');
spdiv.append('下一页');
spdiv.append('末页');
span.appendTo(filedHTML);
spdiv.appendTo(filedHTML);
filedHTML.appendTo(tmenu);
rowContextMenu = this.rowContextMenu = tmenu.menu({
onClick : function(item) {
var fire = $(item.target).attr('fire');
if(fire){
new Function(fire)(); //eval(fire); eval 也是可行的;
}
var pager = grid.datagrid('getPager').pagination('options'); //拿到pager
var pagination = $(item.target).attr('iconCls');
var pageNum = 0
var page = pager.total / pager.pageSize; //总行书 / 每页显示行数 = 总页数
page = Math.ceil(page)
if(pagination == 'pagination-first'){
pageNum = 1;
}
if(pagination == 'pagination-prev'){
pageNum = pager.pageNumber - 1;
}
if(pagination == 'pagination-next'){
pageNum = pager.pageNumber + 1;
}
if(pagination == 'pagination-last'){
pageNum = page;
}
grid.datagrid('getPager').pagination('select',pageNum);
}
});
}else{
}
rowContextMenu.menu('show', {
left : e.pageX,
top : e.pageY
});
var pager = grid.datagrid('getPager').pagination('options'); //拿到pager
var itemFirst = rowContextMenu.menu('findItem','首页');
var itemPrev = rowContextMenu.menu('findItem','上一页');
var itemNext = rowContextMenu.menu('findItem','下一页');
var itemLast = rowContextMenu.menu('findItem','末页');
rowContextMenu.menu('disableItem',itemFirst.target);
rowContextMenu.menu('disableItem',itemPrev.target);
rowContextMenu.menu('disableItem',itemNext.target);
rowContextMenu.menu('disableItem',itemLast.target);
var page = pager.total / pager.pageSize; //总行书 / 每页显示行数 = 总页数
//if(page < 1){ //如果页数小于0
//那么页数 = 1 page = 1;
//}
page = Math.ceil(page)
if(page < 1)
page=page+1;
if(1 < pager.pageNumber && pager.pageNumber < page){
rowContextMenu.menu('enableItem',itemFirst.target);
rowContextMenu.menu('enableItem',itemPrev.target);
rowContextMenu.menu('enableItem',itemNext.target);
rowContextMenu.menu('enableItem',itemLast.target);
}
if(page == pager.pageNumber && pager.pageNumber != 1){
rowContextMenu.menu('enableItem',itemFirst.target);
rowContextMenu.menu('enableItem',itemPrev.target);
}
if(pager.pageNumber == 1 && page != 1){
rowContextMenu.menu('enableItem',itemNext.target);
rowContextMenu.menu('enableItem',itemLast.target);
}
};
$.fn.datagrid.defaults.onRowContextMenu = createGridRowContextMenu;
$.fn.treegrid.defaults.onRowContextMenu = createGridRowContextMenu;