开发者

jquery-jqgrid:How to post value in toolbar search?

This my jqGrid search toolbar script:

<link rel="stylesheet" type="text/css" media="screen" href="jqGrid/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="jqGrid/plugins/ui.multiselect.css" />
    <script src="jqGrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script src="jqGrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="jqGrid/js/jquery.jqGrid.src.js" type="text/javascript"></script>
    <script src="jqGrid/src/jquery.fmatter.js" type="text/javascript"></script>
    <script src="jqGrid/src/jqModal.js" type="text/javasc开发者_如何学Pythonript"></script>

jQuery("#list").jqGrid({
        url:'dounfinish.php',
        datatype: 'json',
        mtype: 'POST',
        colNames:['id','Date', 'Line'],
        colModel :[ 
                   {name:'def_id', index:'def_id', hidden:true, width:55}, 
                   {name:'Problem_date', index:'Problem_date', width:90, editable:true}, 
                   {name:'Line', index:'Line', width:80, align:'right',                   editable:true,search:true,stype:'text',searchoptions:{sopt:['cn']}}],
        pager: jQuery('#pager'),
        rowNum:10,
        rowList:[10,20,30],
        sortname: 'Problem_date',
        sortorder: "desc",
        viewrecords: true,
        imgpath: 'themes/basic/images',
        caption: 'OQC DEFECT DATA'
        });

jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:false,del:false,search:false});
jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, groupOp:'AND'});

And in console:

_search:true
nd:1306513344121
rows:10
page:1
sidx:Problem_date
sord:desc
filters:{"groupOp":"AND","rules":[{"field":"Line","op":"cn","data":"7"}]}

how should I do to post the "data" value? so, I can search data use toolbar search.


jquery-jqgrid:How to post value in toolbar search?


You should just use defaultSearch:'cn' option of the filterToolbar method:

jQuery("#list").jqGrid('filterToolbar', {stringResult: true, defaultSearch:'cn'});

(I removed additionally the options with the default values).

If you use local grid data or the option loadonce:true another jqGrid parameter ignoreCase:true could be also interesting for you.

UPDATED: If you want to use different searching operations for the different columns you should use correct colModel options: searchoptions instead of searchoption ('s' character at the end).

UPDATED 2: How you can verify here if you type bla in the searching toolbar in the 'Line' column the request with the data

_search=true&nd=1306489580463&rows=10&page=1&sidx=Problem_date&sord=desc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22Line%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22bla%22%7D%5D%7D

will be send to the server which will be decoded as

_search=true&nd=1306489580463&rows=10&page=1&sidx=Problem_date&sord=desc&filters={"groupOp":"AND","rules":[{"field":"Line","op":"cn","data":"bla"}]}

So the operation which will be used is "cn".

UPDATED 3: If you use datatype: 'json' without loadonce:true, the server is responsible for sorting, paging and filtering of the data. The jqGrid just send the corresponding information in the parameters (rows, page, sidx, sord, _search:true, filters). If you don't can or don't want to do all this on the server side you can just use loadonce:true and the client part (jqGrid yourself) will change datatype to 'local' after the first load and will do all what you need itself. It work very good if the size of you data small (about 100 rows). You can try this way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜