こんにちはみんな!!!。Jqgrid to 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);
Plzの人たちは私が問題を解決するのを手伝ってくれます..事前に感謝します..