如何在jqGrid的脚本添加到自定义按钮的行?自定义、脚本、按钮、如何在

2023-09-11 01:20:26 作者:烟燎

我想处理自定义按钮,在jqGrid的点击。我有按钮显示出来,但他们被点击的时候,我的功能不会运行。如果我点击jqGrid的外键,运行该脚本。是否jqGrid的消耗按钮点击?不知道我缺少或不理解的东西。这里是电网。究其原因,我没有重新加载整个电网是有在服务器上过多的处理,并且需要手动删除客户端上的行一旦editurl处理送。 见:$(。sendbuttons)点击(函数(){

...

 <风格类型=文本/ CSS>
    .sendbuttons {
    高度:19px;
    宽度:60PX;
    颜色:红色;
    }
    < /风格>

    < SCRIPT LANGUAGE =JavaScript的>

    jQuery的(文件)。就绪(函数(){
    VAR LAST_ROW;
    jQuery的(#gridlist)。jqGrid的({
    网址:manual_responses.php,
    数据类型:JSON,
    colNames:ID,图像,关键字,发送发现,建议送',''],
    colModel:
    {名字:ITEM_ID,索引:ITEM_ID',宽度:45,编辑:假的,隐藏的:真正的},
    {名字:形象,索引:形象,宽度:45},
    {名字:关键字,索引:关键字,宽度:100,可编辑:假},
    {名字:item_found,索引:item_found',宽度:130,可编辑:假},
    {名字:proposed_send,索引:proposed_send',宽度:130,可编辑:真正的,edittype:文本区域,editoptions:{行:2,COLS:37}},
    {名称:选项,索引:选项,宽度:40,编辑:假}
    ]
    的rowNum:40,
    rowList:[20,40,60]
    imgpath:CSS /主题/沙/图像,
    sortname:关键字,
    viewrecords:真正的,
    排序顺序:ASC
    图片说明:建议将
    onSelectRow:功能(ITEM_ID){
    如果(ITEM_ID&安培;&安培;!ITEM_ID == LAST_ROW){
    jQuery的(#gridlist)restoreRow(LAST_ROW)。
    jQuery的(#gridlist)editRow(ITEM_ID,真)。
    LAST_ROW = ITEM_ID;
    }
    },
    loadComplete:函数(){
    //警报('OK,loadComplete运行');
    。VAR的id =的jQuery(#gridlist)getDataIDs();
    对于(VAR I = 0; I< ids.length;我++){
    变种CL = IDS [I]
    发送=<输入级='sendbuttons'ID ='tbuttonSend+ CL +类型=按钮值='发送'/>< BR />中;
    明确=<输入级='sendbuttons'ID ='tbuttonClear+ CL +类型=按钮值='发送'/>< BR />中;
    。jQuery的(#gridlist)setRowData(IDS [I] {选项:发送+明确})
    }
    },
    editurl:item_send.php
    高度:400,
    宽度:796,
    reloadAfterSubmit:假的
    })navGrid('#pager2',{编辑:真正的,加:假的,德尔:假});

    $(sendbuttons)。点击(函数(){
    警报(得1);
    });
    });

    < / SCRIPT>
< /头>
<身体GT;

    <表ID =gridlist级=滚动的cellpadding =0CELLSPACING =0>< /表>
    < D​​IV ID =pager2级=滚动的风格=文本对齐:中心;>< / DIV>

    <输入类型=按钮类='sendbuttons'ID ='323423x'值='去:/>

< /身体GT;
< / HTML>
 

解决方案

显然,click事件,

  $(。sendbuttons)。点击(函数(){
     警报(得1);
});
 

永远不会触发,因为该行的点击消耗它。你可以,但是,把你自己的onclick code的按钮。

 发送=<输入名称='送'级='tweetbuttons'ID ='tbuttonSend+ CL +
       类型=按钮值='发送'
       。的onclick =的jQuery('#list2中)saveRow(+ CL +,函数(){警报(在这里做这')},item_send); />< BR />中;
 
如何在Word2010中添加编号和自定义编号

正如我在评论中讨论,我可以调用saveRow函数的参数。

I am trying to handle the click of custom button in a jqgrid. I have the buttons showing up, but when they are clicked, my function does not run. If I click a button outside the jqgrid, the script runs. Does jqgrid consume the button click? Not sure what I am missing or not understanding. Here is the grid. The reason I am not reloading the entire grid is there is too much processing on the server, and need to manually remove the row on the client once the editurl processes the "send." See: $(".sendbuttons").click(function(){

...

        <style type="text/css">
    	.sendbuttons {
    		height:19px;
    		width:60px;
    		color:red;
    	}
    </style>

    <script language="javascript">

    jQuery(document).ready(function(){
    	var last_row;
    	jQuery("#gridlist").jqGrid({
    		url:'manual_responses.php',
    		datatype: "json",
    		colNames:['ID','Image','Keyword','send Found','Proposed send',''],
    		colModel:[
    			{name:'item_id', index:'item_id', width:45, editable:false, hidden:true},
    			{name:'image', index:'image', width:45},
    			{name:'keyword',index:'keyword', width:100, editable: false},
    			{name:'item_found',index:'item_found', width:130, editable: false},
    			{name:'proposed_send',index:'proposed_send', width:130, editable: true, edittype:"textarea", editoptions:{rows:"2",cols:"37"}},
    			{name:'options',index:'options',width:40,editable: false}
    		],
    		rowNum:40,
    		rowList:[20,40,60],
    		imgpath: 'css/themes/sand/images',
    		sortname: 'keyword',
    		viewrecords: true,
    		sortorder: "asc",
    		caption:"Proposed sends",
    		onSelectRow: function(item_id){
    			if(item_id && item_id!==last_row){
    				jQuery("#gridlist").restoreRow(last_row);
    				jQuery("#gridlist").editRow(item_id,true);
    				last_row=item_id;
    			}
    		},
    		loadComplete: function(){ 
    			//alert('ok, loadComplete running');
    			var ids = jQuery("#gridlist").getDataIDs(); 
    			for(var i=0;i<ids.length;i++){ 
    				var cl = ids[i];
    				send = "<input class='sendbuttons' id='tbuttonSend"+cl+"' type='button' value='Send' /><br />"; 
    				clear = "<input class='sendbuttons' id='tbuttonClear"+cl+"' type='button' value='Send' /><br />"; 
    				jQuery("#gridlist").setRowData(ids[i],{options:send+clear}) 
    			} 
    		}, 
    		editurl: "item_send.php",
    		height:400,
    		width:796,
    		reloadAfterSubmit:false
    	}).navGrid('#pager2',{edit:true,add:false,del:false });

    	$(".sendbuttons").click(function(){
    		alert("got to 1");
    	});
    });

    </script>
</head>
<body>

    <table id="gridlist" class="scroll" cellpadding="0" cellspacing="0"></table>
    <div id="pager2" class="scroll" style="text-align:center;"></div>

    <input type='button' class='sendbuttons' id='323423x' value='go:'/>

</body>
</html>

解决方案

It is apparent that the click event,

$(".sendbuttons").click(function(){
     alert("got to 1");
});

never fires because the click of the row consumes it. You can, however, put in your own onclick code in the button.

send = "<input name='send' class='tweetbuttons' id='tbuttonSend"+cl+
       "' type='button' value='Send' 
       onclick=jQuery('#list2').saveRow("+cl+",function(){alert('made it here')},item_send); /><br />";

As discussed in my comment, I can call the saveRow function with any parameters.