Jquery jqGrid中的工具栏?
我想在jqGrid中创建一个工具栏,其中只包含通常在寻呼机上的按钮 目前我有以下定义Jquery jqGrid中的工具栏?,jquery,jqgrid,jqgrid-asp.net,Jquery,Jqgrid,Jqgrid Asp.net,我想在jqGrid中创建一个工具栏,其中只包含通常在寻呼机上的按钮 目前我有以下定义 $("#foroGrid").jqGrid('navGrid', '#pager', { add: true, addtitle: 'Add Foro', edit: true, edittitle: 'Edit Foro', del: true, deltitle: 'Delete Foro', refresh: true, refreshtitle:
$("#foroGrid").jqGrid('navGrid', '#pager',
{ add: true, addtitle: 'Add Foro',
edit: true, edittitle: 'Edit Foro',
del: true, deltitle: 'Delete Foro',
refresh: true, refreshtitle: 'Refresh data',
search: true, searchtitle: 'Show Filters',
addfunc: addForo, editfunc: editForo, delfunc: deleteForo },
{}, // default settings for edit
{}, // default settings for add
{}, // default settings for delete
{ closeOnEscape: true, multipleSearch: true, closeAfterSearch: true }, // search options
{}
);
我还需要添加其他功能,如“CSV导出”、“PDF导出”、“打印”等
结果是空间将满,我想移动顶部工具栏中的按钮,同时在底部仍然有带导航器的寻呼机和记录计数信息
使用jqGrid是否可以实现此配置?如果要向顶部工具栏添加按钮,必须执行以下操作: 就像我在上一篇文章中说的 将按钮添加到jQGrid工具栏是一个很好的选择 有点棘手。您需要添加 下面的代码位于 jQGrid设置 完成后,您可以使用:
$("#tableID").toolbarButtonAdd("#t_tableID",{caption:"",position:"first",title:"Refresh", align:"right", buttonicon :'ui-icon-refresh', onClickButton:function(){ $("#tableID").trigger("reloadGrid"); } });
如果要向顶部工具栏添加按钮,必须执行以下操作: 就像我在上一篇文章中说的 将按钮添加到jQGrid工具栏是一个很好的选择 有点棘手。您需要添加 下面的代码位于 jQGrid设置 完成后,您可以使用:
$("#tableID").toolbarButtonAdd("#t_tableID",{caption:"",position:"first",title:"Refresh", align:"right", buttonicon :'ui-icon-refresh', onClickButton:function(){ $("#tableID").trigger("reloadGrid"); } });
看看我的老答案。在我看来,这正是你想要的。看看我的老答案。在我看来,它完全符合您的要求。我扩展了脚本,并添加了以相同方式添加标签和锚定的功能。
现在您可以使用:
$("#tableID").toolbarButtonAdd("#t_tableID",{caption:"",position:"first",title:"Refresh", align:"right", buttonicon :'ui-icon-refresh', onClickButton:function(){ $("#tableID").trigger("reloadGrid"); } })
$("#tableID").toolbarLabelAdd("#t_tableID", { caption: "0 Selected", position: "first", title: "", align: "right", id: 'lblSelectedRows' });
$("#tableID").toolbarAncherAdd("#t_tableID", { caption: "Select All", title: "Select All", id: 'btnSelectAll', onClickButton: function() { selectAllRecords(true); } });
以下是库代码:
$.fn.extend({
/*
*
* The toolbar has the following properties
* id of top toolbar: t_<tablename>
* id of bottom toolbar: tb_<tablename>
* class of toolbar: ui-userdata
* elem is the toolbar name to which button needs to be added. This can be
* #t_tablename - if button needs to be added to the top toolbar
* #tb_tablename - if button needs to be added to the bottom toolbar
*/
toolbarButtonAdd: function(elem, p) {
p = $.extend({
caption: "newButton",
title: '',
buttonicon: 'ui-icon-newwin',
onClickButton: null,
position: "last"
}, p || {});
var $elem = $(elem);
var tableString = "<table style='float:left;table-layout:auto;' cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class='ui-toolbar-table'>";
tableString += "<tbody> <tr></tr></table>";
//console.log("In toolbar button add method");
/*
* Step 1: check whether a table is already added. If not add
* Step 2: If there is no table already added then add a table
* Step 3: Make the element ready for addition to the table
* Step 4: Check the position and corresponding add the element
* Step 5: Add other properties
*/
//step 1
return this.each(function() {
if (!this.grid) { return; }
if (elem.indexOf("#") != 0) {
elem = "#" + elem;
}
//step 2
if ($(elem).children('table').length === 0) {
$(elem).append(tableString);
}
//step 3
var tbd = $("<td style=\"padding-left:1px;padding-right:1px\"></td>");
$(tbd).addClass('ui-toolbar-button ui-corner-all').append("<div class='ui-toolbar-div'><span class='ui-icon " + p.buttonicon + "'></span>" + "<span>" + p.caption + "</span>" + "</div>").attr("title", p.title || "")
.click(function(e) {
if ($.isFunction(p.onClickButton)) { p.onClickButton(); }
return false;
})
.hover(
function() { $(this).addClass("ui-state-hover"); },
function() { $(this).removeClass("ui-state-hover"); }
);
if (p.id) { $(tbd).attr("id", p.id); }
if (p.align) { $(elem).attr("align", p.align); }
var findnav = $(elem).children('table');
if (p.position === 'first') {
if ($(findnav).find('td').length === 0) {
$("tr", findnav).append(tbd);
} else {
$("tr td:eq(0)", findnav).before(tbd);
}
} else {
//console.log("not first");
$("tr", findnav).append(tbd);
}
});
},
toolbarLabelAdd: function(elem, p) {
p = $.extend({
caption: "newLabel",
title: '',
id: '',
position: "last"
}, p || {});
var $elem = $(elem);
var tableString = "<table style='float:left;table-layout:auto;' cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class='ui-toolbar-table'>";
tableString += "<tbody> <tr></tr></table>";
/*
* Step 1: check whether a table is already added. If not add
* Step 2: If there is no table already added then add a table
* Step 3: Make the element ready for addition to the table
* Step 4: Check the position and corresponding add the element
* Step 5: Add other properties
*/
//step 1
return this.each(function() {
if (!this.grid) { return; }
if (elem.indexOf("#") != 0) {
elem = "#" + elem;
}
//step 2
if ($(elem).children('table').length === 0) {
$(elem).append(tableString);
}
//step 3
var tbd = $("<td style=\"padding-left:1px;padding-right:1px\"></td>");
$(tbd).addClass('ui-corner-all').append("<div class='ui-toolbar-lbl'><span>" + p.caption + "</span>" + "</div>").attr("title", p.title || "");
if (p.id) { $(tbd).attr("id", p.id); }
if (p.align) { $(elem).attr("align", p.align); }
var findnav = $(elem).children('table');
if (p.position === 'first') {
if ($(findnav).find('td').length === 0) {
$("tr", findnav).append(tbd);
} else {
$("tr td:eq(0)", findnav).before(tbd);
}
} else {
$("tr", findnav).append(tbd);
}
});
},
toolbarAncherAdd: function(elem, p) {
p = $.extend({
caption: "newButton",
title: '',
id: '',
buttonicon: '',
buttonclass : '',
onClickButton: null,
position: "last"
}, p || {});
var $elem = $(elem);
var tableString = "<table style='float:left;table-layout:auto;' cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class='ui-toolbar-table'>";
tableString += "<tbody> <tr></tr></table>";
/*
* Step 1: check whether a table is already added. If not add
* Step 2: If there is no table already added then add a table
* Step 3: Make the element ready for addition to the table
* Step 4: Check the position and corresponding add the element
* Step 5: Add other properties
*/
//step 1
return this.each(function() {
if (!this.grid) { return; }
if (elem.indexOf("#") != 0) {
elem = "#" + elem;
}
//step 2
if ($(elem).children('table').length === 0) {
$(elem).append(tableString);
}
//step 3
var tbd = $("<td style=\"padding-left:1px;padding-right:1px\"></td>"),
iconClass = p.buttonicon.length === 0 ? "" : "<span class='ui-icon " + p.buttonicon + "'></span>";
$(tbd).addClass('ui-toolbar-button ui-corner-all').append("<a class='ui-toolbar-a " + p.buttonClass + "'>" + iconClass + "<span>" + p.caption + "</span>" + "</a>").attr("title", p.title || "")
.click(function(e) {
if ($.isFunction(p.onClickButton)) { p.onClickButton(); }
return false;
});
if (p.id) { $(tbd).attr("id", p.id); }
if (p.align) { $(elem).attr("align", p.align); }
var findnav = $(elem).children('table');
if (p.position === 'first') {
if ($(findnav).find('td').length === 0) {
$("tr", findnav).append(tbd);
} else {
$("tr td:eq(0)", findnav).before(tbd);
}
} else {
//console.log("not first");
$("tr", findnav).append(tbd);
}
});
},
});
$.fn.extend({
/*
*
*工具栏具有以下属性
*顶部工具栏的id:t_
*底部工具栏的id:tb_
*工具栏类:ui userdata
*elem是需要添加按钮的工具栏名称。这可以是
*#t#u tablename-如果需要将按钮添加到顶部工具栏
*#tb_tablename-如果需要将按钮添加到底部工具栏
*/
工具栏按钮添加:功能(元素,p){
p=$.extend({
描述:“纽扣”,
标题:“”,
按钮图标:“ui图标newwin”,
onClickButton:null,
位置:“最后”
},p |{});
变量$elem=$(elem);
var tableString=“”;
表字符串+=“”;
//log(“在工具栏按钮中添加方法”);
/*
*步骤1:检查是否已添加表。如果未添加,则添加
*步骤2:如果没有已添加的表,则添加一个表
*步骤3:使元素准备好添加到表中
*步骤4:检查位置并添加相应的元素
*步骤5:添加其他属性
*/
//第一步
返回此值。每个(函数(){
如果(!this.grid){return;}
if(元素索引of(“#”)等于0){
elem=“#”+elem;
}
//步骤2
if($(elem).children('table')。长度==0){
$(elem).append(表字符串);
}
//步骤3
变量待定=$(“”);
$(待定).addClass('ui-toolbar-button ui-corner-all').append(“+”+p.caption+”).attr(“title”,p.title | |“”)
。单击(功能(e){
if($.isFunction(p.onClickButton)){p.onClickButton();}
返回false;
})
.悬停(
函数(){$(this).addClass(“ui状态悬停”);},
函数(){$(this).removeClass(“ui状态悬停”);}
);
if(p.id){$(待定).attr(“id”,p.id);}
if(p.align){$(elem).attr(“align”,p.align);}
var findnav=$(elem).children('table');
如果(p.position==='first'){
if($(findnav).find('td')。长度==0){
$(“tr”,findnav)。追加(待定);
}否则{
$(“tr td:eq(0)”,findnav)。之前(待定);
}
}否则{
//console.log(“不是第一个”);
$(“tr”,findnav)。追加(待定);
}
});
},
工具栏标签添加:功能(元素,p){
p=$.extend({
标题:“新标签”,
标题:“”,
id:“”,
位置:“最后”
},p |{});
变量$elem=$(elem);
var tableString=“”;
表字符串+=“”;
/*
*步骤1:检查是否已添加表。如果未添加,则添加
*步骤2:如果没有已添加的表,则添加一个表
*步骤3:使元素准备好添加到表中
*步骤4:检查位置并添加相应的元素
*步骤5:添加其他属性
*/
//第一步
返回此值。每个(函数(){
如果(!this.grid){return;}
if(元素索引of(“#”)等于0){
elem=“#”+elem;
}
//步骤2
if($(elem).children('table')。长度==0){
$(elem).append(表字符串);
}
//步骤3
变量待定=$(“”);
$(待定).addClass('ui-corner-all').append(“+p.caption++”).attr(“title”,p.title | |”);
if(p.id){$(待定).attr(“id”,p.id);}
if(p.align){$(elem).attr(“align”,p.align);}
var findnav=$(elem).children('table');
如果(p.position==='first'){
if($(findnav).find('td')。长度==0){
$(“tr”,findnav)。追加(待定);
}否则{
$(“tr td:eq(0)”,findnav)。之前(待定);
}
}否则{
$(“tr”,findnav)。追加(待定);
}
});
},
工具栏:函数(元素,p){
p=$.extend({
描述:“纽扣”,
标题:“”,
id:“”,
钮扣:'',
按钮类:“”,
onClickButton:null,
位置:“最后”
},p |{});
变量$elem=$(elem);
var tableString=“”;
表字符串+=“”;
/*
*步骤1:检查是否已添加表。如果未添加,则添加
*步骤2:如果没有已添加的表,则添加一个表
*步骤3:使元素准备好添加到表中
*步骤4:检查位置并添加相应的元素
*步骤5:添加其他属性
*/
//第一步
返回此值。每个(函数(){
如果(!this.grid){return;}
if(元素索引of(“#”)等于0){
elem=“#”+elem;
}
//步骤2