Jqgrid工具栏搜索无法在滚动分页中工作

时间:2014-03-14 09:37:16

标签: jquery codeigniter jqgrid pagination scroll-paging

我正在使用jqgrid并且我的工具栏搜索在我使用滚动分页之前正在工作但是现在它在滚动分页后不起作用。我使用参数loadonce:true;经过大量的谷歌搜索,但总记录没有加载。我的代码如下

$(document).ready(function(){
var ageCheckbox = document.getElementById('sent_all_message');
ageCheckbox.onchange = function() { 
    var grid = $("#grid");
    if(this.checked){                          
        grid.jqGrid('resetSelection');
        var ids = grid.getDataIDs();
        for (var i=0, il=ids.length; i < il; i++) {
            grid.jqGrid('setSelection',ids[i], true);
        }
         $('.cbox').attr('disabled', true);
        $('#gview_grid #cb_grid').attr('checked',true).attr('disabled',true);
    }else{            
         grid.jqGrid('resetSelection');
         $('#gview_grid #cb_grid').attr('checked',false).attr('disabled',false);
         $('.cbox').attr('disabled', false);   
    }
};
$.extend(jQuery.jgrid.defaults, {
            prmNames: {
                id: "rowid", page: "page", rows: "rows",
                oper: "oper", sort: "sidx", order: "sord",
                search : "search"
            }
        });
jQuery("#grid").jqGrid({ //set your grid id        
  //  data: mydata, //insert data from the data object we created above 
    url:'adminCreateMessageGrid',
    datatype: "json",        

    colNames:['Id','First name','Last Name','Specialty','Username','Email'], //define column names
    colModel:[
        {name:'id',index:'id',hidden:true,width:50,align:"center"},
        {name:'first_name', index:'first_name',sortable:true, width:100,align:"center"},
        {name:'last_name', index:'last_name',sortable:true, width:100,align:"center"},
        {name:'description', index:'description',sortable:true, width:100,align:"center",stype:"select",
        searchoptions: {
        sopt:['eq'],        
        value: ":All;1:Family Practice;2:Obstetrics",          
       // defaultValue: "1"         
        }},                 
        {name:'user_name', index:'user_name',sortable:true,width:100,align:"center"},
        {name:'email', index:'email',sortable:true,width:170,align:"center"}
    ], //define column models        
    pager: '#pager', //set your pager div id
    rowNum: 50,
    sortname: 'first_name', //the column according to which data is to be sorted; optional
    scroll:1,
    multiSort:true,
    sortable:true,
  //  loadonce : true,      
    ignoreCase: true,
    scrollOffset: 1,
    gridview: true,     
    height: 450,
    width: 875,  
    sortorder: 'asc',         
    viewrecords: true, //if true, displays the total number of records, etc. as: "View X to Y out of Z” optional
    multiselect: true,
    shrinkToFit:true,        
    onSelectRow: function (id) {
        var  arrID = new Array();
        $('.cbox').each(function(){
            if($(this).attr('checked') == 'checked'){                    
                var name = $(this).attr('id');
                var id = $('#'+name).closest('tr.jqgrow').attr('id');   
                arrID.push(id);                    
            }
        });
         $('#selectedUser').val(arrID);
       // console.log(arrID.toSource());
    },
    caption:"Select Users", //title of grid
   loadComplete: function () {
    var objRows = $("#list_accounts tr"); 
var objHeader = $("#list_accounts .jqgfirstrow td"); 

if (objRows.length > 1) { 
    var objFirstRowColumns = $(objRows[1]).children("td"); 
    for (i = 0; i < objFirstRowColumns.length; i++) { 
        $(objFirstRowColumns[i]).css("width", $(objHeader[i]).css("width")); 
    } 
} 
     $('#lui_grid').remove();
   }
});

// jQuery的(&#34;#网格&#34)setGridParam({的rowNum:50})。。触发器(&#34; reloadGrid&#34); jQuery(&#34; #grid&#34;)。jqGrid(&#34; filterToolbar&#34;,{     multipleSearch:真实,     recreateFilter:真实,     searchOperators:true,
    stringResult:true,     覆盖:假的,     searchOnEnter:false,     defaultSearch:&#34; bw&#34;,

});
 });

我的分页代码如下

 $Page = $_GET['page'];
    $OrderByOption = $_GET['sidx'];
    $OrderByOptionSort = $_GET['sord'];
    if (isset($OrderByOption) && $OrderByOption != '') {
        if (isset($OrderByOptionSort) && $OrderByOptionSort != '') {
            $OrderBy = 'ORDER BY users.first_name' . $OrderByOption . ' ' . $OrderByOptionSort;
        }
    }
    $Limit = 50;      
    $arrAllUserData = $this->User_model->messagegrcountid();
    $PageCount = 0;
    if (count($arrAllUserData) > 0) {
        if ($Limit != 0) {
            $PageCount = ceil(count($arrAllUserData) / $Limit);
        } else {
            $PageCount = count($arrAllUserData);
        }
    }       
    if ($Page > $PageCount)
        $Page = $PageCount;        
    if ($Page < 1)
        $Page = 1; 
    $Start = ($Limit * $Page) - $Limit;  
    $arrUserData = $this->User_model->messagegrid($Start,$Limit,$OrderBy);
    $ResponceData = new stdClass(); 
    $ResponceData->total = $PageCount;
    $ResponceData->page = $Page;       
    $ResponceData->records = count($arrAllUserData);
    for ($Index = 0; $Index < count($arrUserData); $Index++) {
            $ResponceData->rows[$Index]['cell'] = array($arrUserData[$Index]['id'],$arrUserData[$Index]['first_name'],$arrUserData[$Index]['last_name'],$arrUserData[$Index]['description'],$arrUserData[$Index]['user_name'],$arrUserData[$Index]['email']);
        }
    echo json_encode($ResponceData);  

请建议我的答案

1 个答案:

答案 0 :(得分:0)

  

如果 loadonce 设置为 true ,则网格仅从服务器加载数据   一次(使用适当的数据类型)。第一次请求后,   数据类型参数会自动更改为本地和所有   操作在客户端进行。寻呼机的功能   (如果存在)被禁用。

在您的情况下,虚拟滚动仅在loadonce设置为true时才有效。您必须修改服务器端调用以立即返回整个记录。或者编写自己的逻辑来进行滚动条分页(我认为这会稍微复杂一些)。

请参阅more information

的jqgrid文档