snaif_lx
snaif_lx
2015-10-22 14:13
采纳率: 80%
浏览 3.4k
已采纳

easyui combogrid 如何在回车之后才开始检索

加query参数是动态检索,如果在输入关键字的文本框上输入后敲回车再开始检索?

 $('#cg').combogrid('textbox').keydown(function (e) {
                   if (e.keyCode == 13) {
                       alert('aa');
                       var keyValue = $('#cg').combogrid('textbox').val();
                       var queryParams = $('#cg').combogrid("grid").datagrid('options').queryParams;
                       queryParams.keyword = keyword;
                       $('#cg').combogrid("grid").datagrid('options').queryParams = queryParams;
                       //重新加载
                       $('#cg').combogrid("grid").datagrid("reload");

                       $('#cg').combogrid("setValue", keyValue);
                       //将查询条件存入隐藏域
                       $('#hdKeyword').val(keyValue)
                   }
               });

捆绑的事件不执行,是不是压根就不是textbox?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • showbo
    已采纳
    
            $('#cc').combogrid('textbox').unbind()//先解绑所有事件,要不输入的内容找不到匹配项,回车时输入框内容会被清空
            .keydown(function (e) {
                if (e.keyCode == 13) {
                    var keyValue = $('#cc').combogrid('textbox').val();
                    var queryParams = $('#cc').combogrid("grid").datagrid('options').queryParams;
                    queryParams.keyword = keyValue;//keyword;///这里变量名搞错了,是keyValue,不是keyword
                    //下面这句不需要,因为queryParams是对象,地址引用,可以直接更改optinos.queryParams的内容
                    //$('#cc').combogrid("grid").datagrid('options').queryParams = queryParams;
                    //重新加载
                    $('#cc').combogrid("grid").datagrid("reload");
    
                    $('#cc').combogrid("setValue", keyValue);
                    //将查询条件存入隐藏域
                    //$('#hdKeyword').val(keyValue)
                }
            });
    
    点赞 评论
  • devmiao
    devmiao 2015-10-23 00:47

    combogrid('textbox')找到了么?调试下

    点赞 评论
  • snaif_lx
    snaif_lx 2015-10-23 09:31

    $('#cg').combogrid('textbox').unbind()//先解绑所有事件,要不输入的内容找不到匹配项,回车时输入框内容会被清空
    .keydown(function (e) {
    //alert('bb');
    if (e.keyCode == 13) {

                       var keyValue = $('#cg').combogrid('textbox').val();
                      // alert(keyValue);
                       var queryParams = $('#cg').combogrid("grid").datagrid('options').queryParams;
                       queryParams.keyword = keyValue;
                       $('#cg').combogrid("grid").datagrid('options').queryParams = queryParams;
                       //重新加载
                       $('#cg').combogrid("grid").datagrid("reload");
    
                       $('#cg').combogrid("setValue", keyValue);
                       //将查询条件存入隐藏域
                       $('#hdKeyword').val(keyValue)
                   }
               });
    
    点赞 评论
  • snaif_lx
    snaif_lx 2015-10-24 08:54

    if (e.keyCode == 40) { //------------键盘下键
    var selected = $('#cg').combogrid('grid').datagrid('getSelected');
    if (selected) {
    //取得选中行的rowIndex
    var index = $('#cg').combogrid('grid').datagrid('getRowIndex', selected);
    //向下移动到当页最后一行为止
    if (index < $('#cg').combogrid('grid').datagrid('getData').rows.length - 1) {
    $('#cg').combogrid('grid').datagrid('selectRow', index + 1);
    }
    } else {
    $('#cg').combogrid('grid').datagrid('selectRow', 0);
    }
    }
    if (e.keyCode == 38) { //------------键盘上键
    //取得选中行
    var selected = $('#cg').combogrid('grid').datagrid('getSelected');
    if (selected) {
    //取得选中行的rowIndex
    var index = $('#cg').combogrid('grid').datagrid('getRowIndex', selected);
    //向上移动到第一行为止
    if (index > 0) {
    $('#cg').combogrid('grid').datagrid('selectRow', index - 1);
    }
    } else {
    var rows = $('#cg').combogrid('grid').datagrid('getRows');
    $('#cg').combogrid('grid').datagrid('selectRow', rows.length - 1);
    }
    }

    点赞 评论

相关推荐