0

嗨伙计们!!!我开发了一个 Jqgrid 到 diaplay 数据库。现在我想添加 JQgrid 过滤器工具栏以根据用户需要细化数据,所以我添加了过滤器工具栏。但是过滤器工具栏仅在“loadonce:true”表示本地与第一页数据时使用,而我希望它适用于整个数据库......来自服务器响应......

下面我发布我的代码以供参考...

$(function () {
        $("#UsersGrid").jqGrid({
            url: 'getGriddahico.ashx',
            datatype: 'json',
            height: 250,
            colNames: ['UserID', 'username', 'ordinal', 'authcode', 'extension', 'trunk', 'dialnumber', 'dialdate', 'dialtime', 'duration', 'destination', 'price', 'toc'],
            colModel: [
                    { name: 'UserID', index: 'UserID', width: 100, sortable: true, align: 'center',hidden:true },
                    { name: 'username', width: 100, sortable: true, align: 'center' },
                    { name: 'ordinal', width: 100, sortable: true, align: 'center' },
                    { name: 'authcode', width: 100, sortable: true },
                    { name: 'extension', width: 100, sortable: true, align: 'center' },
                    { name: 'trunk', width: 100, sortable: true, align: 'center' },
                    { name: 'dialnumber', width: 100, sortable: true, align: 'center' },
                    { name: 'dialdate', width: 100, sortable: true, align: 'center' },
                    { name: 'dialtime', width: 100, sortable: true, align: 'center' },
                    { name: 'duration', width: 100, sortable: true, align: 'center' },
                    { name: 'destination', width: 100, sortable: true, align: 'center' },
                    { name: 'price', width: 100, sortable: true, align: 'center' },
                    { name: 'toc', width: 150, sortable: true, align: 'center' }
                ],
            rowNum: 100,
            rowList: [100, 200, 300],
            pager: '#UsersGridPager',
            sortname: 'username',
            //loadonce: true,
            viewrecords: true,
            ignoreCase:true,
            sortorder: 'asc',
            autowidth: true,
            toppager: true,
            height: '100%'

        });

        $("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false, search: false });

        jQuery("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });
    });

我的处理程序(.ashx)文件代码:

                        int start=0;
                        int total=0;
                        int total_pages =0;


                        int intpage =Convert.ToInt32(request["page"]);
                        int limit=Convert.ToInt32(request["rows"]);
                       // int intpage = new Integer(request.getParameter("page"));
                        //int limit = new Integer(request.getParameter("rows"));



                        string sidx = request["sidx"];
                        string sord = request["sord"];

                       // String sidx = request.getParameter("sidx");
                        //String sord = request.getParameter("sord");

                        String strQuery="";
                        String json ="";

                      Boolean rc ;


                      MySqlDataReader rs;
                        //ResultSet rs = null;

                        if(sidx ==""){
                            sidx ="1";
                        }


                        /*-----------------------------------Conexión a la base de datos MySql-------------------------------------------*/
                        conexion  conexiondb = new conexion();
                        conexiondb.Conectar();
                        /*-----------------------------------------------------------------------------------------------------------*/

                        total = conexiondb.countRec("price", "processeddata_table");

                        if( total>0 ) {
                            double d = Math.Ceiling( (double)(total) / (double)(limit) );
                            total_pages = (int)(d);
                        } else {
                            total_pages = 0;
                        }

                        if (intpage > total_pages) {
                            intpage=total_pages;
                        }

                        start = limit * intpage - limit; 

                        if(start < 0 ){
                            start = 0;
                        }

                        //strQuery = "SELECT username,ordinal,authcode,extension,trunk,dialnumber,dialdate,dialtime,duration,destination,price,toc FROM processeddata_table ORDER BY username asc";

                        strQuery = "SELECT username,ordinal,authcode,extension,trunk,dialnumber,dialdate,dialtime,duration,destination,price,toc FROM processeddata_table ORDER BY " + sidx + " " + sord + " LIMIT " + start + " , " + limit;

                        rs = conexiondb.Consulta(strQuery);

                        total = conexiondb.countRec("price", "processeddata_table");

                        response.ContentType="text/x-json";
                        response.ContentType = "charset=utf-8";
                        //response.ContentEncoding="utf-8";
                        response.AddHeader("Pragma", "no-cache");
                        response.AddHeader("Cache-Control", "no-cache, must-revalidate");
                        response.AddHeader("Pragma", "no-cache");

                        json ="";
                        json = json + "{\n";
                        json = json + " \"page\":\""+intpage+"\",\n";
                        json = json + "\"total\":"+total_pages+",\n";
                        json = json + "\"records\":"+total+",\n";
                        json = json + "\"rows\": [";
                        rc =false;

                        while(rs.Read()){

                            if(rc){
                                json = json + ",";
                            }
                            json = json + "\n{";
                            json = json + "\"price\":\"" + Convert.ToInt32(rs["price"]) + "\",";
                            json = json + "\"cell\":[" + Convert.ToInt32(rs["price"]) + "";
                            json = json + ",\"" + Convert.ToString(rs["username"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["ordinal"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["authcode"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["extension"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["trunk"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["dialnumber"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["dialdate"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["dialtime"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["duration"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["destination"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["price"]) + "\"";
                            json = json + ",\"" + Convert.ToString(rs["toc"]) + "\"]";
                            json = json + "}";

                            rc=true;
                        }
                        json = json +"]\n";

                        json = json +"}";


                        HttpContext.Current.Response.Write(json);

请大家帮我解决这个问题..提前谢谢..

4

1 回答 1

0

如果您使用loadonce: true选项,则数据将立即从服务器加载,以后对先前加载的数据的搜索、排序和分页将由 jqGrid在本地实现。

If you don't want to use loadonce: true option then you have to implement the features in your server code. In the answer for example you can find an example of such implementation in the code which uses ASHX like you do.

于 2013-01-31T07:05:02.477 回答