一、前言

       新年新气象,转眼今年就28了,不知道今年能不能把妹成功呢?哈哈哈!上班第一天,部门Web技术主管给每个同事都发了红包鼓励大家今年加油,我作为新转入部门员工不能给团队掉链子,要加紧学习跟上队伍。大家都下班了,我安安静静总结之前BootStrap的知识内容。

二、内容

<div>
<table id="ExampleTable" data-toggle="table" class="table table-hover"
data-url="/api/Controller/Action"
data-method="post" //Post方式获取数据
data-side-pagination="server" //服务器分页
data-pagination="true" //是否支持分页
data-query-params-type="" //如果支持RestFul需要写'limit'
data-query-params = qcondition> //查询条件
<thead>
<tr>
<th data-field="field1" data-valign="middle">字段1</th>
<th data-field="field2" data-valign="middle" data-class="field2-class" data-formatter="Formatfield2" data-events="operateField2Events">字段2</th>
<th data-formatter="FormatItem3" data-valign="middle">项目3</th>
</tr>
</thead>
</table>
</div>

BootStrap的<table>标签:

主要说明的是data-query-params这个属性,它是用来对获取到的服务器数据进行筛选的,我们可以在js中这么写:

var qcondition = function (params) {
var temp = {
        FilterText: filterValue,
        Condition: params.searchText,
        PageSize: params.pageSize,
        PageIndex: params.pageNumber - 1
    };
    return temp;
};

那么在Controller中,我们就需要根据qcondition获取相应的数据:


public class QueryDataInfo
{  
    public string FilterText { get; set; }
    public string Condition { get; set; }
    public int PageIndex { get; set; }
    public int PageSize { get; set; }
}
[HttpPost]
public HttpResponseMessage Action(QueryDataInfo dataInfo)
{
long recordCount = ;
IList<DataInfo> list = Query(dataInfo, out recordCount);
return ResultJson.BuildJsonResponse(new { total = recordCount, rows = list }, MessageType.None, string.Empty);
} public IList<DataInfo> Query(QueryDataInfo dataInfo, out long recordCount)
{
     IList<DataInfo> list = new List<DataInfo>();
     string[] includePath = {"ForeignKey"};   
list = DataRepository.LoadPageList(out recordCount,
dataInfo.PageIndex * dataInfo.PageSize,
dataInfo.PageSize,
            d => d.Text == dataInfo.FilterText,
            o => o.ID,
false,
includePath);   
    return list;
} //以下代码写在基抽象类中
public IList<TEntity> LoadPageList<TKey>(out long count,
int pageIndex,
int pageSize,
Expression<Func<TEntity, bool>> expression = null,
Expression<Func<TEntity, TKey>> orderBy = null,
bool ascending = true,
params string[] includePath)
{
     IQueryable<TEntity> defaultQuery = Query(expression,
includePath);
     if (orderBy != null)
     {
        if (ascending)
            defaultQuery = defaultQuery.OrderBy(orderBy);
        else
            defaultQuery = defaultQuery.OrderByDescending(orderBy);
     }
     count = defaultQuery.Count();
     defaultQuery = defaultQuery.Skip(pageIndex).Take(pageSize);
     return defaultQuery.ToList();
} public IQueryable<TEntity> Query(Expression<Func<TEntity, bool>> expression = null,
params string[] includePath)
{
     IQueryable<TEntity> defaultQuery = mobjContext.Context.Set<TEntity>();
     if (includePath != null)
     {
        foreach (string path in includePath)
        {
             if (!string.IsNullOrEmpty(path))
             {
                  defaultQuery = defaultQuery.Include(path);
             }
         }
     }      if (expression != null)
         defaultQuery = defaultQuery.Where(expression);
     return defaultQuery;
}

BootStrap的<th>标签:

data-field: 数据字段,对应返回的对象中的字段。

data-class: 该<th>标签的class,一般用于该列的自定义css样式

<style>
.field2-class {
min-height: 0px;
}
</style>

data-formatter: 对该列数据进行格式上的变化

function Formatfield2(value, row, index) {
return '<span class="link-name item-name">' + row.Name + '</span><input type="hidden" class="hiddenRowid" value='+row.ID+' />';
}

data-events:  该列数据事件,如点击该列的某个字段会发生何种事件

window.operateField2Events = {
'click .class-name': function (e, value, row, index) {
//do something
}
}

官方文档:

http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/

三、结尾

       以后会持续更新关于BootStrap的相关内容!

【BootStrap】Table的基本使用的更多相关文章

  1. BootStrap table使用

    bootstrap table git address https://github.com/wenzhixin/bootstrap-table 引入文件 <link rel="sty ...

  2. bootstrap Table 中给某一特定值设置table选中

    bootstrap Table 中给某一特定值设置table选中 需求: 如图所示:左边地图人员选定,右边表格相应选中. 功能代码: //表格和图标联动 function changeTableSel ...

  3. JS组件系列——表格组件神器:bootstrap table

    前言:之前一直在忙着各种什么效果,殊不知最基础的Bootstrap Table用法都没有涉及,罪过,罪过.今天补起来吧.上午博主由零开始自己从头到尾使用了一遍Bootstrap Table ,遇到不少 ...

  4. JS组件系列——表格组件神器:bootstrap table(二:父子表和行列调序)

    前言:上篇 JS组件系列——表格组件神器:bootstrap table 简单介绍了下Bootstrap Table的基础用法,没想到讨论还挺热烈的.有园友在评论中提到了父子表的用法,今天就结合Boo ...

  5. JS组件系列——表格组件神器:bootstrap table(三:终结篇,最后的干货福利)

    前言:前面介绍了两篇关于bootstrap table的基础用法,这章我们继续来看看它比较常用的一些功能,来个终结篇吧,毛爷爷告诉我们做事要有始有终~~bootstrap table这东西要想所有功能 ...

  6. JS组件系列——Bootstrap Table 冻结列功能IE浏览器兼容性问题解决方案

    前言:最近项目里面需要用到表格的冻结列功能,所谓“冻结列”,就是某些情况下表格的列比较多,需要固定前面的几列,后面的列滚动.遗憾的是,bootstrap table里自带的fixed column功能 ...

  7. JS组件系列——Bootstrap Table 表格行拖拽

    前言:之前一直在研究DDD相关知识,好久没更新JS系列文章了.这两天做了一个简单的业务需求,觉得效果还可以,今天在这里分享给大家,欢迎拍砖~~ 一.业务需求及实现效果 项目涉及到订单模块,那天突然接到 ...

  8. JS组件系列——Bootstrap Table 表格行拖拽(二:多行拖拽)

    前言:前天刚写了篇JS组件系列——Bootstrap Table 表格行拖拽,今天接到新的需要,需要在之前表格行拖拽的基础上能够同时拖拽选中的多行.博主用了半天时间研究了下,效果是出来了,但是感觉不尽 ...

  9. 后台系统组件:一丶bootstrap table

    http://www.cnblogs.com/landeanfen/p/4976838.html (bootstrap table) http://www.cnblogs.com/landeanfen ...

  10. Bootstrap Table Examples

    The examples of bootstrap table http://bootstrap-table.wenzhixin.net.cn/examples/ http://www.jq22.co ...

随机推荐

  1. Memached、Redis、Mongodb的区别

    性能 ​ • 性能都很高,redis和memached差不多 > Mongodb 操作 ​ • Memached:数据结构单一,只有key/value数据结构 ​ • Redis有五种数据类型 ...

  2. 关于UC浏览器兼容scroll事件问题

    经过本人查阅无数资料,最终得出一个比较简单,具有一定兼容性的结果. $(window).scroll(function( ) { var scrollTop = document.documentEl ...

  3. NO--13微信小程序,左右联动

    写在前面: 从2016年张小龙发布微信小程序这种新的形态,到2017年小程序的不温不火,再到今年小程序的大爆发,从一度刷爆朋友圈的‘头脑王者’,再到春节聚会坐在一起的火爆小游戏“跳一跳",都 ...

  4. python基础_字符编码

    字符编码的历史 阶段一:现代计算机起源于美国,最早诞生也是基于英文考虑的ASCII 阶段二:为了满足中文,中国人定制了GBK 阶段三:各国有各国的标准,就会不可避免地出现冲突,结果就是,在多语言混合的 ...

  5. IntelliJ IDEA 自动编译功能无法使用,On 'update' action:选项里面没有update classes and resources这项

    https://zhidao.baidu.com/question/1381265197230335740.html

  6. 树莓派3+rtl8812au开启monitor模式

    首先要有一块树莓派,要有一块rtl8812au的网卡. 这个网卡是支持monitor模式的,但是我原来装的驱动驱动在raspbian上开启monitor模式时提示,找不到设备. 然后换了一个驱动 ht ...

  7. 2017-2018-2 1723 『Java程序设计』课程 结对编程练习_四则运算 第二周

    一.结对对象 姓名:侯泽洋 学号:20172308 担任角色:驾驶员(侯泽洋) 伙伴第二周博客地址 二.本周内容 (一)继续编写上周未完成代码 1.本周继续编写代码,使代码支持分数类计算 2.相关过程 ...

  8. 安卓端通过http对Mysql进行增删改查

    各类it学习视频,大家都可以看看哦!我自己本人都是通过这些来学习it只知识的! 下面是视频链接转自:http://www.cnblogs.com/yzxk/p/4749440.html Android ...

  9. android 的helloworld没跑起来 原因

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com. ...

  10. Mac 下搭建 Apache 服务器

    Apache作为最流行的Web服务器端软件之一,它的优点与地位不言而喻.下面介绍下在Mac下搭建Apache服务器的步骤: (1)“前往” –>”个人” (2)在你的个人目录下新建一个文件夹,改 ...