先来看一下某一位大佬留下的easyUI的API对datagrid绑定数据的两种方式的介绍。

虽然精简,但是,很具有“师傅领进门,修行靠个人”的精神,先发自内心的赞一个。

但是,很多人和小编一样,第一次接触easyUI,对这么精简的问题,问题颇多,因此,小编在这里献上一份个人认为比较详尽的版本

通过HTML/JSP页面初始化表格,JS绑定数据

在JSP中定义table和列名,以及列属性。

列属性却不定义在data-option属性中,field对应的字段名,需和后台返回的字段名相同。

    <table id="good_tables" style="height: 484px;">
<thead>
<tr>
<th data-options="field:'id',sortable:true">商品ID</th>
<th data-options="field:'goodsName'">商品名称</th>
<th data-options="field:'supplier'">供应商</th>
</tr>
</thead>
</table>

在JS文件中获取并绑定数据

$(document).ready(function () {
initGoodsTable();
}); function initGoodsTable(){
$('#good_tables').datagrid({
nowrap: true,
autoRowHeight: true,
striped: true,
fitColumns: true,
collapsible: true,
url: 'xxx',
border: false,
idField: 'id',
selectOnCheck: true,
singleSelect: true,
width:'100%' ,
resizable:true,
remoteSort: false,
pagination: true,
pageSize: 10,
rowNumbers: false,
success:function (data) {
var rows=[];
for(var i=0; i< data.length; i++){
rows.push({
id:data[i].id,
goodsName:data[i].goodsName,
supplier:data[i].supplier
});
}
$("#good_tables").datagrid({data:rows});
},
error:function () {
$.messager.alert("提示","获取数据失败");
}
});
}

通过JS获取并绑定数据

在JSP中定义table

<table id="good_tables" style="height: 484px;"></table>

在JS页面中初始化列名和数据

$(document).ready(function () {
initGoodsTable();
}); function initGoodsTable(){
$('#good_tables').datagrid({
nowrap: true,
autoRowHeight: true,
striped: true,
fitColumns: true,
collapsible: true,
url: 'xxx',
border: false,
idField: 'id',
selectOnCheck: true,
singleSelect: true,
width:'100%' ,
resizable:true,
remoteSort: false,
columns: [[
{
field: 'id',
title: '商品ID',
align: 'center',
formatter: function (value) {
return value;
}
},
{
field: 'goodsName',
title: '商品名称',
align: 'center',
formatter: function (value) {
return value;
}
}, {
field: 'supplier',
title: '供应商',
align: 'center',
formatter: function (value,row) {
return value;
}
}
]],
pagination: true,
pageSize: 10,
rowNumbers: false
});
}

以上就是小编的分享,觉得有用的小伙伴,记得点赞!

easyUI之datagrid绑定后端返回数据的两种方式的更多相关文章

  1. angular学习笔记(三)-视图绑定数据的两种方式

    绑定数据有两种方式: <!DOCTYPE html> <html ng-app> <head> <title>2.2显示文本</title> ...

  2. springMVC返回数据的四种方式

    转自:https://blog.csdn.net/itcats_cn/article/details/82119673 springMVC返回数据的四种方式:第一种,通过request.setAttr ...

  3. SparkStreaming与Kafka,SparkStreaming接收Kafka数据的两种方式

    SparkStreaming接收Kafka数据的两种方式 SparkStreaming接收数据原理 一.SparkStreaming + Kafka Receiver模式 二.SparkStreami ...

  4. 【代码笔记】iOS-向服务器传JSON数据的两种方式

    一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...

  5. C++读取字符串数据的两种方式

    C++读取字符串数据的两种方式 对于同样的样例输入: ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Ride ...

  6. SparkStreaming获取kafka数据的两种方式:Receiver与Direct

    简介: Spark-Streaming获取kafka数据的两种方式-Receiver与Direct的方式,可以简单理解成: Receiver方式是通过zookeeper来连接kafka队列, Dire ...

  7. Ajax请求数据的两种方式

    ajax 请求数据的两种方法,有需要的朋友可以参考下. 实现ajax 异步访问网络的方法有两个.第一个是原始的方法,第二个是利用jquery包的 原始的方法不用引入jquery包,只需在html中编写 ...

  8. 获取Executor提交的并发执行的任务返回结果的两种方式/ExecutorCompletionService使用

    当我们通过Executor提交一组并发执行的任务,并且希望在每一个任务完成后能立即得到结果,有两种方式可以采取: 方式一: 通过一个list来保存一组future,然后在循环中轮训这组future,直 ...

  9. ORACLE导入大量数据的两种方式比较

    不管是开发还是测试,工作中经常需要去批量新增测试数据,但是大量数据的新增速度有时候让我们苦不堪言,下面通过两种方式完成oracle数据的批量新增,比较两种方式的效率. 第一种方式:采用工具导入sql文 ...

随机推荐

  1. Kera高层API

    目录 Keras != tf.keras Outline1 Metrics Step1.Build a meter Step2.Update data Step3.Get Average data C ...

  2. iOS开发 - 多线程实现方案之NSThread篇

    NSThread API //类方法:创建一个线程 + (void)detachNewThreadWithBlock:(void (^)(void))block API_AVAILABLE(macos ...

  3. Git - Merge: refusing to merge unrelated histories

    场景 我在本地有个代码仓库local-A,本地仓库local-A已经和一个远程仓库remote-A关联了. 接着我又在GitHub上新建了一个仓库remote-B,我希望将本地仓库local-A的本地 ...

  4. go系列(2)- go框架beego以及命令bee的使用

    上篇写了go的安装和GOPATH的配置,linux下go的安装 ,现在就看看如何用框架. 1.进入GOPATH的目录 cd /data/work/go 2.下载beego,通过go get go ge ...

  5. Codeforces Round #396 (Div. 2) B

    Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 li ...

  6. 洛谷 P1067 多项式输出

    P1067 多项式输出 模拟,很坑的那种 var i,n:longint; a:array[1..105] of integer; begin readln(n); for i:=1 to n+1 d ...

  7. MySQL之select简单使用

    Select * from table_name Select column_name_1,column_name_2 from table_name Select * from student wh ...

  8. 在Asp.net MVC4 中使用SimpleMembershipProvider

    一.创建MVC4项目 运行Visual Studio Express 2012 for Web,新建ASP.NET MVC4 Web 应用程序,命名为“Demo”,选择空模版.这样就创建了一个干净的M ...

  9. nopCommerce - asp.net开源商城

    nopcommerce官网 http://nopcommerce.codeplex.com/ nopCommerce is a open source e-commerce solution that ...

  10. Android Theme.Dialog 到光 AppCompatDialog

    我用在我的 style.xml 作为主要应用程序主题 <style name="AppTheme" parent="Theme.AppCompat.Light&qu ...