Javascript 单击按钮更改JQGrid单元格值
我正在asp.NETWebForms中使用jqgrid。我有一个名为Actions的列,其中有一个按钮Add,我想当我点击Add按钮时,单元格值应该被改变。就像我在这个单元格中有一个按钮一样,当我点击add按钮时,它会随着文本而改变。请引导我。下面给出了我正在使用的代码Javascript 单击按钮更改JQGrid单元格值,javascript,jquery,html,asp.net,jqgrid,Javascript,Jquery,Html,Asp.net,Jqgrid,我正在asp.NETWebForms中使用jqgrid。我有一个名为Actions的列,其中有一个按钮Add,我想当我点击Add按钮时,单元格值应该被改变。就像我在这个单元格中有一个按钮一样,当我点击add按钮时,它会随着文本而改变。请引导我。下面给出了我正在使用的代码 <table id="jQGridDemo"> </table> <div id="jQGridDemoPager"> </div> jQuery(“#jQGridDemo
<table id="jQGridDemo">
</table>
<div id="jQGridDemoPager">
</div>
jQuery(“#jQGridDemo”).jqGrid({
url:'HttpHandlers/CustomersList.ashx',
数据类型:“json”,
colNames:['Opted-In','Name','Email','Filter Matches','Customer Id','Actions',],
colModel:[
{name:'OptedIn',index:'OptedIn',width:40,align:'center',stype:'text',formatter:OptedInValue},
{name:'CustomerName',index:'CustomerName',width:90,stype:'text',sortable:true},
{name:'CustomerEmail',index:'CustomerEmail',宽度:110,stype:'text',可排序:true},
{name:'FilterLetter',index:'FilterLetter',宽度:60},
{name:'CustomerId',index:'CustomerId',宽度:60,隐藏:true},
{name:'Actions',index:'Actions',editable:true,width:60,align:'center',formatter:ButtonValue}
],
宽度:600,
身高:300,
rowNum:30,
mtype:'获取',
有一次:是的,
行列表:[30,60,90],
寻呼机:“#jQGridDemoPager”,
sortname:“OptedIn”,
viewrecords:是的,
排序器:“asc”,
标题:“客户名单”
});
函数按钮值(单元格值、选项、行对象){
var filterLetter=rowObject.filterLetter;
var-link='';
如果(过滤器文字==“A”){
链接='添加';
}否则{
链接='Remove';
}
返回链接;
}
函数OptedInValue(单元格值、选项、行对象){
var optedIn=rowObject.optedIn;
var-link='';
如果(optedIn==true){
链接='';
}
else if(optedIn==false){
链接='';
}
返回链接;
};
函数removeGridCustomer(id,rowId){
调试器
var rowData=$('jQGridDemo').jqGrid('getRowData',rowId);
rowData.Actions='12321';
$('#jQGridDemo').jqGrid('setRowData',rowId,rowData);
$('#').val($('#').val()+id+',');
UpdateFiltersforucsremove(id);
}
我研究这个问题,发现下面的解决方案就是我的解决方案
function ButtonValue(cellvalue, options, rowObject) {
var filterLetter = rowObject.FilterLetter;
var Id = qs("id");
var link = '';
if (Id != 0) {
link = '<div id="addbutton"><button type="button" onclick=addGridCustomer(' + rowObject.CustomerId + ',' + options.rowId + ')>Add</button></div>';
}
else {
link = '<div id="removecustomer"><button type="button" onclick=removeGridCustomer(' + rowObject.CustomerId + ',' + options.rowId + ')>Remove</button></div>';
}
return link;
}
function OptedInValue(cellvalue, options, rowObject) {
var optedIn = rowObject.OptedIn;
var link = '';
if (optedIn == true) {
link = '<img title="View ' + rowObject.CustomerName + ' ' + '" src="/images/icn_alert_success.png" />';
}
else if (optedIn == false) {
link = '<img title="View ' + rowObject.CustomerName + ' ' + '" src="/images/icn_alert_error.png" />';
}
return link;
};
function removeGridCustomer(id, rowId) {
debugger
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div button').hide();
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div').append('to be removed ..');
$('#<% = hdCustomer.ClientID %>').val($('#<% = hdCustomer.ClientID %>').val() + id + ',');
//Update Filters in case of removal
UpdateFiltersForCusRemove(id);
}
function addGridCustomer(id, rowId) {
$('#<% = hdCustomer.ClientID %>').val($('#<% = hdCustomer.ClientID %>').val() + id + ',');
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div button').hide();
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div').append('to be added ..');
//Update Filters in case of removal
UpdateFiltersForCusAdd(id);
}
function UpdateFiltersForCusAdd(a) {
var filterLtr = $("#lblF" + a).text().trim();
var count = 0;
count = parseInt($("#filterL" + filterLtr).text().trim()) - 1
$("#filterL" + filterLtr).text(count);
TotalCustomers(+1);
}
函数按钮值(单元格值、选项、行对象){
var filterLetter=rowObject.filterLetter;
var Id=qs(“Id”);
var-link='';
如果(Id!=0){
链接='添加';
}
否则{
链接='Remove';
}
返回链接;
}
函数OptedInValue(单元格值、选项、行对象){
var optedIn=rowObject.optedIn;
var-link='';
如果(optedIn==true){
链接='';
}
else if(optedIn==false){
链接='';
}
返回链接;
};
函数removeGridCustomer(id,rowId){
调试器
$(“#jQGridDemo tr”).eq(rowId).children().eq(5).find('div button').hide();
$(“#jQGridDemo tr”).eq(rowId).children().eq(5).find('div').append('to remove..);
$('#').val($('#').val()+id+',');
//删除时更新过滤器
UpdateFiltersforucsremove(id);
}
函数addGridCustomer(id,rowId){
$('#').val($('#').val()+id+',');
$(“#jQGridDemo tr”).eq(rowId).children().eq(5).find('div button').hide();
$(“#jQGridDemo tr”).eq(rowId).children().eq(5).find('div').append('to added..);
//删除时更新过滤器
UpdateFiltersforuchsad(id);
}
函数updateFiltersforuchsad(a){
var filterLtr=$(“#lblF”+a).text().trim();
var计数=0;
count=parseInt($(“#filterL”+filterLtr).text().trim())-1
$(“#filterL”+filtertr).text(计数);
客户总数(升1),;
}
看看这个,我已经试过了,但不起作用。为什么不起作用?发生了什么与您预期的结果不同的情况?你有错误吗?我想隐藏我的按钮并在按钮处显示文本。为了更好地理解,请使用Fiddle(jsfiddle.net)发布你的问题。
function ButtonValue(cellvalue, options, rowObject) {
var filterLetter = rowObject.FilterLetter;
var Id = qs("id");
var link = '';
if (Id != 0) {
link = '<div id="addbutton"><button type="button" onclick=addGridCustomer(' + rowObject.CustomerId + ',' + options.rowId + ')>Add</button></div>';
}
else {
link = '<div id="removecustomer"><button type="button" onclick=removeGridCustomer(' + rowObject.CustomerId + ',' + options.rowId + ')>Remove</button></div>';
}
return link;
}
function OptedInValue(cellvalue, options, rowObject) {
var optedIn = rowObject.OptedIn;
var link = '';
if (optedIn == true) {
link = '<img title="View ' + rowObject.CustomerName + ' ' + '" src="/images/icn_alert_success.png" />';
}
else if (optedIn == false) {
link = '<img title="View ' + rowObject.CustomerName + ' ' + '" src="/images/icn_alert_error.png" />';
}
return link;
};
function removeGridCustomer(id, rowId) {
debugger
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div button').hide();
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div').append('to be removed ..');
$('#<% = hdCustomer.ClientID %>').val($('#<% = hdCustomer.ClientID %>').val() + id + ',');
//Update Filters in case of removal
UpdateFiltersForCusRemove(id);
}
function addGridCustomer(id, rowId) {
$('#<% = hdCustomer.ClientID %>').val($('#<% = hdCustomer.ClientID %>').val() + id + ',');
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div button').hide();
$("#jQGridDemo tr").eq(rowId).children().eq(5).find('div').append('to be added ..');
//Update Filters in case of removal
UpdateFiltersForCusAdd(id);
}
function UpdateFiltersForCusAdd(a) {
var filterLtr = $("#lblF" + a).text().trim();
var count = 0;
count = parseInt($("#filterL" + filterLtr).text().trim()) - 1
$("#filterL" + filterLtr).text(count);
TotalCustomers(+1);
}