ParamQuery(jQuery Grid Plugin - PQGrid, jQuery插件)


優點:開源,能自己修改代碼,皮膚也能自己定制,能夠單獨引入項目(不需要復制進一堆無關的東西),對於簡單的后台項目比較適用
官網:http://paramquery.com/
InfoQ上對ParamQuery的描述如下:

排序
分頁瀏覽
可以調整數據欄的大小
可以調整表格的高度和寬度
自定義主題
隱藏或顯示列
像Excel那樣凍結任意多列
顯示任意數據源格式,像HTML、數組、XML、JSON等
可以用於任意服務端框架,像ASP.NET、MVC3、JSP、JSF、PHP等等
虛擬滾動和渲染
直接編輯單元格
在所有主流瀏覽器(IE 6+、Firefox、Chrome、Opera等等)上擁有一致的外觀和功能

 

最簡單的Demo:

效果圖如下:

實現步驟:
先在html的head中加入對jQuery和jQuery UI的引用:

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>       <!--用了CDN鏈接(自適應http, https的切換),所以src的開頭直接用了"//"-->
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>  <!--同上-->

 

再加入對Param Query Grid的引用:

<link rel="stylesheet" href="/Content/pqgrid/pqgrid.min.css" />           <!--這個css文件必須引用,無論你是用了皮膚,還是沒有用到皮膚,都要引用-->
<script type="text/javascript" src="/Scripts/pqgrid.min.js" ></script>    <!--這個js文件必須引用-->

 

增加腳本代碼:

$(function () {
                var data = [    [1, 'Exxon Mobil', '339,938.0', '36,130.0'],
                                [2, 'Wal-Mart Stores', '315,654.0', '11,231.0'],
                                [3, 'Royal Dutch Shell', '306,731.0', '25,311.0'],
                                [4, 'BP', '267,600.0', '22,341.0'],
                                [5, 'General Motors', '192,604.0', '-10,567.0'],
                                [6, 'Chevron', '189,481.0', '14,099.0'],
                                [7, 'DaimlerChrysler', '186,106.3', '3,536.3'],
                                [8, 'Toyota Motor', '185,805.0', '12,119.6'],
                                [9, 'Ford Motor', '177,210.0', '2,024.0'],
                                [10, 'ConocoPhillips', '166,683.0', '13,529.0'],
                                [11, 'General Electric', '157,153.0', '16,353.0'],
                                [12, 'Total', '152,360.7', '15,250.0'],
                                [13, 'ING Group', '138,235.3', '8,958.9'],
                                [14, 'Citigroup', '131,045.0', '24,589.0'],
                                [15, 'AXA', '129,839.2', '5,186.5'],
                                [16, 'Allianz', '121,406.0', '5,442.4'],
                                [17, 'Volkswagen', '118,376.6', '1,391.7'],
                                [18, 'Fortis', '112,351.4', '4,896.3'],
                                [19, 'Crédit Agricole', '110,764.6', '7,434.3'],
                                [20, 'American Intl. Group', '108,905.0', '10,477.0']
                            ];

                var obj = {};
                obj.width = 700;
                obj.height = 400;
                obj.colModel = [{ title: "Rank", width: 100, dataType: "integer" },
                    { title: "Company", width: 200, dataType: "string" },
                    { title: "Revenues ($ millions)", width: 150, dataType: "float", align: "right" },
                    { title: "Profits ($ millions)", width: 150, dataType: "float", align: "right" }];
                obj.dataModel = { data: data };
                $("#grid_array").pqGrid(obj);

            });

 

最后,在要顯示的地方加入div元素,用來顯示表格:

<div id="grid_array"></div>

 

搞定,運行就能看到效果。


加入Theme皮膚的Demo:

效果圖如下:

實現步驟:
js代碼邏輯部分沒有任何變動,哈哈。
html的head部分增加那么一句style引用,就搞定了,如下:

<link rel="stylesheet" href="/Content/pqgrid/pqgrid.min.css" />               <!- 這句就是增加的,其他沒有任何變動...哈哈 ->
<link rel="stylesheet" href="/Content/pqgrid/themes/peach/pq-grid.css" />
<script type="text/javascript" src="/Scripts/pqgrid.min.js" ></script>

 

 就那么搞定了...

 

Tips: 本文中所用到的css、js文件都是官網下載中自帶的,下載url:http://paramquery.com/download


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM