0

0

使用FlexiGrid实现Extjs表格效果方法分享_jquery

php中文网

php中文网

发布时间:2016-05-16 16:26:17

|

1319人浏览过

|

来源于php中文网

原创

近一段时间extjs真的是风光无限好,只要是个做crm/hrm之类的企业现在都在琢磨怎么在项目中用它,不过兄弟我可是不敢,原因很简单:太大/太笨/源码不好调试。但是对于extjs漂亮的表格与功能的强大,实在是让我垂涎三尺,记得以前有个老外同志写过一个类似的extjs的jquery插件,所以就在jquery的插件海洋中一顿海找,呵呵,还真让我找到了。看来还是我的jquery好,小巧简单好像一部好的汽车引擎,我想要什么就可以自已diy,真是方便。总体方案在网络传输上不超过80kb,速度比500kb大小的extjs不知道要小上多少哪。。。



下载地址:http://code.google.com/p/flexigrid/

不过由于FlexiGrid在互联网上的大部分资料都是用PHP或者java写的,所以兄弟简单的对它进行了改制,也做了一个山寨版的Extjs表格实现,希望对大家有帮助。

基本使用:

1 基本使用是非常简单的,只需要加入Jquery库与FlexiGrid的JS即可以对表格进行格式化与美化.

复制代码 代码如下:




--%>

2 加入需要格式化的表格即可

复制代码 代码如下:


     最简单的flexigrid表格-1


 
    
        
            
            
            
            
        
    
    
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
    
 

                 Col 1
            

                 Col 2
            

                 Col 3 is a long header name
            

                 Col 4
            

                 This is data 1 with overflowing content
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

 


 


 


     最简单的flexigrid表格-2


 
    
        
            
            
            
            
        
    
    
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
            
            
        
    
 

                 Col 1
            

                 Col 2
            

                 Col 3 is a long header name
            

                 Col 4
            

                 This is data 1 with overflowing content
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            

                 This is data 1
            

                 This is data 2
            

                 This is data 3
            

                 This is data 4
            


为了增加FlexiGrid的基本使用效果,我们可以通过参数对其进行基本的调整

自定义表头

具体代码实现:

MagicLight AI
MagicLight AI

AI动画视频创作平台

下载

复制代码 代码如下:


自定义折叠,自定义排序的实现

复制代码 代码如下:


高级使用:

1 分页用到的存储过程

复制代码 代码如下:

Create PROCEDURE [dbo].[spAll_ReturnRows]
        (
            @SQL nVARCHAR(4000),
            @Page int,
            @RecsPerPage int,
            @ID VARCHAR(255),
            @Sort VARCHAR(255)
        )
        AS
        DECLARE @Str nVARCHAR(4000)
        SET @Str='SELECT   TOP '+
            CAST(@RecsPerPage AS VARCHAR(20))+
            ' * FROM ('+@SQL+') T WHERE T.'+
            @ID+
            ' NOT IN (SELECT   TOP '+
            CAST((@RecsPerPage*(@Page-1)) AS VARCHAR(20))+
            ' '+
            @ID+
            ' FROM ('
            +@SQL+
            ') T9 ORDER BY '+
            @Sort+
            ') ORDER BY '+
            @Sort
        PRINT @Str
        EXEC sp_ExecuteSql @Str

2 异步JSON数据传输实现

复制代码 代码如下:

 using System;
 using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
 using System.Data.SqlClient;
 using System.Linq;
 using System.Text;
 using System.Web;
 using System.Web.Services;
 using Newtonsoft.Json;
 namespace GridDemo
 {
     ///
     /// $codebehindclassname$ 的摘要说明
     ///

     [WebService(Namespace = "http://tempuri.org/")]
     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
     public class GetDataSource4 : IHttpHandler
     {
         public void ProcessRequest(HttpContext context)
         {
             context.Response.ContentType = "text/plain";
             //得到当前页
             string CurrentPage = context.Request["page"];
             //得到每页显示多少
             string PageShowLimit = context.Request["rp"];
             //得到主键
             string TableID = context.Request["sortname"];
             //得到排序方法
             string OrderMethod = context.Request["sortorder"];
             //得到要过滤的字段
             string FilterField = context.Request["qtype"];
             //得到要过滤的内容
             string FilterFieldContext;
             if (context.Request.Form["letter_pressed"] == null)
             {
                 FilterFieldContext = "";
             }
             else
             {
                 FilterFieldContext = context.Request["letter_pressed"];
             }
             //得到表的总行数
             string TableRowCount = SqlHelper.ExecuteScalar(ConfigurationManager.AppSettings["SQL2"],
                                     CommandType.Text,
                                     "select count(*) from Person.Address"
                                    ).ToString();
             //得到主SQL
             SqlParameter SQL = new SqlParameter("@SQL", SqlDbType.NVarChar);
             //SQL.Value = "SELECT  * FROM Person.Address";
             if (FilterFieldContext.Length == 0 || FilterField.Length == 0)
             {
                 SQL.Value = "SELECT  AddressID,AddressLine1,AddressLine2,PostalCode,City FROM Person.Address";
             }
             else
             {
                 string[] tmp = FilterField.Split(',');
                 SQL.Value = "SELECT  AddressID,AddressLine1,AddressLine2,PostalCode,City FROM Person.Address where " + tmp[0] + " like '" + FilterFieldContext + "%'";
             }
             SqlParameter Page = new SqlParameter("@Page", SqlDbType.Int);
             Page.Value = Convert.ToInt32(CurrentPage);
             SqlParameter RecsPerPage = new SqlParameter("@RecsPerPage", SqlDbType.Int);
             RecsPerPage.Value = Convert.ToInt32(PageShowLimit);
             SqlParameter ID = new SqlParameter("@ID", SqlDbType.VarChar);
             ID.Value = TableID;
             SqlParameter Sort = new SqlParameter("@Sort", SqlDbType.VarChar);
             Sort.Value = TableID;
             //得到表
             DataTable returnTable = SqlHelper.ExecuteDataset(ConfigurationManager.AppSettings["SQL2"],
                         CommandType.StoredProcedure, "spAll_ReturnRows",
                         new SqlParameter[]
                             {
                                 SQL,Page,RecsPerPage,ID,Sort
                             }).Tables[0];
             context.Response.Write(DtToSON2(returnTable, CurrentPage, TableRowCount));
         }
         ///
         /// JSON格式转换
         ///

         /// DataTable表
         /// 当前页
         /// 总计多少行
         ///
         public static string DtToSON2(DataTable dt, string page, string total)
         {
             StringBuilder jsonString = new StringBuilder();
             jsonString.AppendLine("{");
             jsonString.AppendFormat("page: {0},\n", page);
             jsonString.AppendFormat("total: {0},\n", total);
             jsonString.AppendLine("rows: [");
             for (int i = 0; i              {
                 jsonString.Append("{");
                 jsonString.AppendFormat("id:'{0}',cell:[", dt.Rows[i][0].ToString());
                 for (int j = 0; j                  {
                     if (j == dt.Columns.Count - 1)
                     {
                         jsonString.AppendFormat("'{0}'", dt.Rows[i][j].ToString());
                     }
                     else
                     {
                         jsonString.AppendFormat("'{0}',", dt.Rows[i][j].ToString());
                     }
                     if (j == dt.Columns.Count - 1)
                     {
                         jsonString.AppendFormat(",'{0}'", "");
                     }
                 }
                 jsonString.Append("]");
                 if (i == dt.Rows.Count - 1)
                 {
                     jsonString.AppendLine("}");
                 }
                 else
                 {
                     jsonString.AppendLine("},");
                 }
             }
             jsonString.Append("]");
             jsonString.AppendLine("}");
             return jsonString.ToString();
         }
         public bool IsReusable
         {
             get
             {
                 return false;
             }
         }
     }
 }

3 页面实现

复制代码 代码如下:

 
 ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 http://www.w3.org/1999/xhtml">
 
    
    
    
    
    
    
    
    

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

32

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

23

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

16

2026.01.31

golang 循环遍历
golang 循环遍历

本专题整合了golang循环遍历相关教程,阅读专题下面的文章了解更多详细内容。

5

2026.01.31

Golang人工智能合集
Golang人工智能合集

本专题整合了Golang人工智能相关内容,阅读专题下面的文章了解更多详细内容。

6

2026.01.31

2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

268

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

195

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

170

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

85

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
CSS3 教程
CSS3 教程

共18课时 | 5.1万人学习

Excel 教程
Excel 教程

共162课时 | 15万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.4万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号