jqGrid下載/使用

介紹
  • Caption layer
  • Header layer
  • Body layer
  • Navigation layer


    如圖所示
下載

1.在Download Builder官方頁面下載jqGrid砸西,可以選擇自己需要的組件下載术吗,獲得一個定制的版本瞳步。
2.在ThemeRoller官方頁面下下載主題导饲,獲取jQuery UI主題文件们镜。

使用

解壓下載好的壓縮包,在項目的根目錄下建立相應的文件夾,將文件放入文件夾中率拒,目錄如圖示:


如圖所示

添加如下代碼

    <link rel="stylesheet" href="jQueryUI/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="jqGrid/css/ui.jqgrid.css" />
     
    <script src="jqGrid/js/jquery-1.11.0.min.js" type="text/javascript"></script>
    <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>
實例

在數(shù)據(jù)庫中建表倍谜,準備數(shù)據(jù)

建表
CREATE TABLE invheader (                                                     
  invid int(11) NOT NULL AUTO_INCREMENT,                                             
  invdate date NOT NULL,                                                          
  client_id int(11) NOT NULL,                                                     
  amount decimal(10,2) NOT NULL DEFAULT '0.00',                                   
  tax decimal(10,2) NOT NULL DEFAULT '0.00',                                      
  total decimal(10,2) NOT NULL DEFAULT '0.00',                                    
  note char(100) DEFAULT NULL,                                 
  PRIMARY KEY  (invid) 
);

測試數(shù)據(jù)dataupload,xls文件轉(zhuǎn)為csv導入數(shù)據(jù)庫迈螟。

HTML文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>My First Grid</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<style type="text/css">
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style>
 
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
 
<script type="text/javascript">
$(function () {
    $("#list").jqGrid({
        url: "example.php",
        datatype: "xml",
        mtype: "GET",
        colNames: ["Inv No", "Date", "Amount", "Tax", "Total", "Notes"],
        colModel: [
            { name: "invid", width: 55 },
            { name: "invdate", width: 90 },
            { name: "amount", width: 80, align: "right" },
            { name: "tax", width: 80, align: "right" },
            { name: "total", width: 80, align: "right" },
            { name: "note", width: 150, sortable: false }
        ],
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: "invid",
        sortorder: "desc",
        viewrecords: true,
        gridview: true,
        autoencode: true,
        caption: "My first grid"
    }); 
}); 
</script>
 
</head>
<body>
    <table id="list"><tr><td></td></tr></table> 
    <div id="pager"></div> 
</body>
</html>
Property Description
url 服務端地址
datatppe 返回的數(shù)據(jù)格式xml或者json
mtype 請求方法GET或者POST
colNames 表格中的列名
colModel 定義每列的屬性
pager 表格的導航條
rowNum 行數(shù)
rowList 導航條的顯示數(shù)據(jù)的條數(shù)
sortname 根據(jù)哪個字段進行排序
viewrecords 在導航條顯示數(shù)據(jù)條數(shù)
caption 表格名稱
PHP文件
<?php
//include the information needed for the connection to MySQL data base server.
// we store here username, database and password

// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
$page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];

// sorting order - at first time sortorder
$sord = $_GET['sord'];

// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;

// connect to the MySQL database server
$db = mysql_connect('127.0.0.1', 'root', '') or die("Connection Error: " . mysql_error());

// select the database
mysql_select_db('test') or die("Error connecting to db.");

// calculate the number of rows for the query. We need this for paging the result
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
    $total_pages = ceil($count/$limit);
} else {
    $total_pages = 0;
}

// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;

// calculate the starting position of the rows
$start = $limit*$page - $limit;

// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;

// the actual query for the grid data
$SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());

// we should set the appropriate header information. Do not forget this.
header("Content-type: text/xml; charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";

// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $s .= "<row id='". $row['invid']."'>";
    $s .= "<cell>". $row['invid']."</cell>";
    $s .= "<cell>". $row['invdate']."</cell>";
    $s .= "<cell>". $row['amount']."</cell>";
    $s .= "<cell>". $row['tax']."</cell>";
    $s .= "<cell>". $row['total']."</cell>";
    $s .= "<cell><![CDATA[". $row['note']."]]></cell>";
    $s .= "</row>";
}
$s .= "</rows>";

echo $s;
?>

效果如圖


My First Grid

友情提示:關(guān)閉php的display errors選項,否則會因為數(shù)據(jù)庫的問題報錯尔崔。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末答毫,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子季春,更是在濱河造成了極大的恐慌洗搂,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,820評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件载弄,死亡現(xiàn)場離奇詭異耘拇,居然都是意外死亡,警方通過查閱死者的電腦和手機宇攻,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,648評論 3 399
  • 文/潘曉璐 我一進店門惫叛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人逞刷,你說我怎么就攤上這事嘉涌。” “怎么了夸浅?”我有些...
    開封第一講書人閱讀 168,324評論 0 360
  • 文/不壞的土叔 我叫張陵仑最,是天一觀的道長。 經(jīng)常有香客問我题篷,道長词身,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,714評論 1 297
  • 正文 為了忘掉前任番枚,我火速辦了婚禮法严,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘葫笼。我一直安慰自己深啤,他們只是感情好,可當我...
    茶點故事閱讀 68,724評論 6 397
  • 文/花漫 我一把揭開白布路星。 她就那樣靜靜地躺著溯街,像睡著了一般诱桂。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上呈昔,一...
    開封第一講書人閱讀 52,328評論 1 310
  • 那天挥等,我揣著相機與錄音,去河邊找鬼堤尾。 笑死肝劲,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的郭宝。 我是一名探鬼主播辞槐,決...
    沈念sama閱讀 40,897評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼粘室!你這毒婦竟也來了榄檬?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,804評論 0 276
  • 序言:老撾萬榮一對情侶失蹤衔统,失蹤者是張志新(化名)和其女友劉穎鹿榜,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體缰冤,經(jīng)...
    沈念sama閱讀 46,345評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡犬缨,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,431評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了棉浸。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片怀薛。...
    茶點故事閱讀 40,561評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖迷郑,靈堂內(nèi)的尸體忽然破棺而出枝恋,到底是詐尸還是另有隱情,我是刑警寧澤嗡害,帶...
    沈念sama閱讀 36,238評論 5 350
  • 正文 年R本政府宣布焚碌,位于F島的核電站,受9級特大地震影響霸妹,放射性物質(zhì)發(fā)生泄漏十电。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,928評論 3 334
  • 文/蒙蒙 一叹螟、第九天 我趴在偏房一處隱蔽的房頂上張望鹃骂。 院中可真熱鬧,春花似錦罢绽、人聲如沸畏线。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,417評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽寝殴。三九已至蒿叠,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間蚣常,已是汗流浹背市咽。 一陣腳步聲響...
    開封第一講書人閱讀 33,528評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留抵蚊,地道東北人魂务。 一個月前我還...
    沈念sama閱讀 48,983評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像泌射,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子鬓照,可洞房花燭夜當晚...
    茶點故事閱讀 45,573評論 2 359

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,297評論 25 707
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫熔酷、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,120評論 4 61
  • 精忠報國兵陣明豺裆,戎狄不敢岳家軍拒秘。 血戰(zhàn)沙場英雄夢,立國難安小人心臭猜。 【2016躺酒,9,8蔑歌。三古月南】
    三古月南閱讀 115評論 0 1
  • 今天下午有些許時間羹应,便看了一場電影,六年之前的次屠,名字叫做《奪命深淵》园匹,看著片名比較恐怖,其實不然劫灶。更多是一...
    不曾沉默閱讀 1,265評論 0 0
  • 同蚯蚓的戰(zhàn)斗 也是由于斷網(wǎng)幾天的緣故,對于我這是個不怎么開心的秋天涌穆。小說已經(jīng)四天沒更新了怔昨。柜...
    海上飛嬰閱讀 330評論 0 1