javascript - 如何将脚本添加到 jqgrid 中行上的自定义按钮?

标签 javascript jquery ajax client jqgrid

我正在尝试处理 jqgrid 中自定义按钮的点击。我显示了按钮,但是单击它们时,我的功能没有运行。如果我单击 jqgrid 外部的按钮,脚本就会运行。 jqgrid 是否消耗按钮点击?不确定我缺少或不理解的内容。这是网格。我没有重新加载整个网格的原因是服务器上的处理太多,一旦 editurl 处理“发送”,就需要手动删除客户端上的行。 参见:$(".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>

最佳答案

很明显,点击事件,

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

永远不会触发,因为单击该行会消耗它。但是,您可以在按钮中放入自己的 onclick 代码。

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 />"; 

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

关于javascript - 如何将脚本添加到 jqgrid 中行上的自定义按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1384685/

相关文章:

javascript - 使用onClick从javascript创建html按钮调用一个参数的方法

javascript - HTML 保护密码字段

javascript - 一个 HTML 页面上的多个 Three.js CSS3D 场景,分子示例

javascript - 使用全选复选框移动数据

javascript - 复选框颜色变为灰色

javascript - Highcharts 不起作用

javascript - Action 创建者完成之前路线更改

javascript - 类型错误 : Cannot read property 'credential' of undefined with firebase reauthenticateWithCredential

php - 使用 javascript 循环 php 无法获得正确的结果顺序

javascript - 如何通过单击按钮全屏播放 YouTube 嵌入式视频?