Jquery ui 带有自定义列的jqgrid
我在应用程序中使用Jqgrid。我想创建一个包含两个按钮的列。我想在列中添加,因为按钮可能会根据行的数据而有所不同。我在谷歌上搜索了一下,发现只有使用自定义格式设置选项创建一个按钮,但它只出现在双击一行或编辑一行时,但我希望它显示在列本身上。任何包含信息的帮助或链接都将不胜感激。下面是我的网格代码。 需要使用按钮创建另一列 编辑:Jquery ui 带有自定义列的jqgrid,jquery-ui,jqgrid,jqgrid-formatter,Jquery Ui,Jqgrid,Jqgrid Formatter,我在应用程序中使用Jqgrid。我想创建一个包含两个按钮的列。我想在列中添加,因为按钮可能会根据行的数据而有所不同。我在谷歌上搜索了一下,发现只有使用自定义格式设置选项创建一个按钮,但它只出现在双击一行或编辑一行时,但我希望它显示在列本身上。任何包含信息的帮助或链接都将不胜感激。下面是我的网格代码。 需要使用按钮创建另一列 编辑: var grid = $(gridId); grid.jqGrid({ data: gridData, datatype: "local",
var grid = $(gridId);
grid.jqGrid({
data: gridData,
datatype: "local",
gridview: true,
colModel: [
{
label: 'Employee Name', name: 'employeeName', width: 195, editable:true,
sortable:true, editrules:{required:true}
},
{
label: 'Address', name: 'address', width: 170, editable:true,
sortable:true,
editrules:{required:true}
},
{
label: 'Department', name: 'department', width: 120, editable:true,
sortable:true,
edittype:'custom',
editoptions: {
'custom_element' : populateReturnTypeAutocomplete,
'custom_value' : autocomplete_value
},
editrules:{required:true}
},
});
好的,把这个加到你的表上
{label: 'My Custom Column', name: 'custom', index:'custom' width: 120}
现在在gridComplete或loadComplete中添加此代码
var grid = $("#grid"),
iCol = getColumnIndexByName(grid,'custom'); // 'custom' - name of the actions column
grid.children("tbody")
.children("tr.jqgrow")
.children("td:nth-child("+(iCol+1)+")")
.each(function() {
$("<div>",
{
title: "button1",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click:
handle your click function here
}
).css({"margin-left": "5px", float:"left"})
.addClass("ui-pg-div ui-inline-save")
.attr('id',"customId")
.append('<span class="ui-button-icon-primary ui-icon ui-icon-disk"></span>')
.appendTo($(this).children("div"));
$("<div>",
{
title: "custombutton 2",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click:
handle click here
}
).css({"margin-left": "5px", float:"left"})
.addClass("ui-pg-div ui-inline-custom")
.attr('id',"customButton2")
.append('<span class="ui-button-icon-primary ui-icon ui-icon-circle-check"></span>')
.appendTo($(this).children("div"));
var grid=$(“#grid”),
iCol=getColumnIndexByName(网格,'custom');/'自定义”-操作列的名称
表格.儿童(“tbody”)
.儿童(“tr.jqgrow”)
.儿童(“td:n个儿童(“+(iCol+1)+”))
.each(函数({
$("",
{
标题:“按钮1”,
mouseover:function(){
$(this.addClass('ui-state-hover');
},
mouseout:function(){
$(this.removeClass('ui-state-hover');
},
点击:
在这里处理你的点击功能
}
).css({“左边距”:“5px”,float:“left”})
.addClass(“ui pg div ui内联保存”)
.attr('id','customId')
.append(“”)
.appendTo($(this.children)(“div”);
$("",
{
标题:“自定义按钮2”,
mouseover:function(){
$(this.addClass('ui-state-hover');
},
mouseout:function(){
$(this.removeClass('ui-state-hover');
},
点击:
点击这里
}
).css({“左边距”:“5px”,float:“left”})
.addClass(“ui pg div ui内联自定义”)
.attr('id',“customButton2”)
.append(“”)
.appendTo($(this.children)(“div”);
现在,我在这里添加的这些图标将与jqueryui.css一起使用,您需要在脚本中添加一个函数,该函数将在上述代码的第一行中为u获取“自定义”列索引
var getColumnIndexByName = function(grid,columnName) {
var cm = grid.jqGrid('getGridParam','colModel'), i=0,l=cm.length;
for (; i<l; i+=1) {
if (cm[i].name===columnName) {
return i; // return the index
}
}
return -1;
};
var getColumnIndexByName=函数(网格,columnName){
var cm=grid.jqGrid('getGridParam','colModel'),i=0,l=cm.length;
对于(;i好的,将此添加到您的colModal中
{label: 'My Custom Column', name: 'custom', index:'custom' width: 120}
现在在gridComplete或loadComplete中添加此代码
var grid = $("#grid"),
iCol = getColumnIndexByName(grid,'custom'); // 'custom' - name of the actions column
grid.children("tbody")
.children("tr.jqgrow")
.children("td:nth-child("+(iCol+1)+")")
.each(function() {
$("<div>",
{
title: "button1",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click:
handle your click function here
}
).css({"margin-left": "5px", float:"left"})
.addClass("ui-pg-div ui-inline-save")
.attr('id',"customId")
.append('<span class="ui-button-icon-primary ui-icon ui-icon-disk"></span>')
.appendTo($(this).children("div"));
$("<div>",
{
title: "custombutton 2",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click:
handle click here
}
).css({"margin-left": "5px", float:"left"})
.addClass("ui-pg-div ui-inline-custom")
.attr('id',"customButton2")
.append('<span class="ui-button-icon-primary ui-icon ui-icon-circle-check"></span>')
.appendTo($(this).children("div"));
var grid=$(“#grid”),
iCol=getColumnIndexByName(网格,'custom');/'custom'-操作列的名称
表格.儿童(“tbody”)
.儿童(“tr.jqgrow”)
.儿童(“td:n个儿童(“+(iCol+1)+”))
.each(函数({
$("",
{
标题:“按钮1”,
mouseover:function(){
$(this.addClass('ui-state-hover');
},
mouseout:function(){
$(this.removeClass('ui-state-hover');
},
点击:
在这里处理你的点击功能
}
).css({“左边距”:“5px”,float:“left”})
.addClass(“ui pg div ui内联保存”)
.attr('id','customId')
.append(“”)
.appendTo($(this.children)(“div”);
$("",
{
标题:“自定义按钮2”,
mouseover:function(){
$(this.addClass('ui-state-hover');
},
mouseout:function(){
$(this.removeClass('ui-state-hover');
},
点击:
点击这里
}
).css({“左边距”:“5px”,float:“left”})
.addClass(“ui pg div ui内联自定义”)
.attr('id',“customButton2”)
.append(“”)
.appendTo($(this.children)(“div”);
现在,我在这里添加的这些图标将与jqueryui.css一起使用,您需要在脚本中添加一个函数,该函数将在上述代码的第一行中为u获取“自定义”列索引
var getColumnIndexByName = function(grid,columnName) {
var cm = grid.jqGrid('getGridParam','colModel'), i=0,l=cm.length;
for (; i<l; i+=1) {
if (cm[i].name===columnName) {
return i; // return the index
}
}
return -1;
};
var getColumnIndexByName=函数(网格,columnName){
var cm=grid.jqGrid('getGridParam','colModel'),i=0,l=cm.length;
对于(;iA自定义格式化程序应满足您的需要,请编辑您的问题并添加网格声明和自定义格式化程序的代码,我们将更好地为您提供帮助。自定义格式化程序应满足您的需要,请编辑您的问题并添加网格声明和自定义格式化程序的代码,我们将更好地为您提供帮助谢谢Piyush Sardana你的密码真的帮了我这就是我要找的谢谢Piyush Sardana你的密码真的帮了我这就是我要找的。