×

easyui教程 easyui jquery easyui

如何用jquery easyui 数据网格?jQuery Easyui实现左右布局

admin admin 发表于2022-05-31 13:59:52 浏览117 评论0

抢沙发发表评论

如何用jquery easyui 数据网格


使用数据网格的详细视图,用户可以展开一行来显示附加的详细信息。任何内容都可以加载作为行详细,子网格也可以动态加载。本教程将向您展示如何在主网格上创建一个子网格。
jQuery EasyUI最新试用版下载请猛戳 》》

查看jQuery EasyUI演示
Step 1:创建主数据网格

Item ID
Product ID
List Price
Unit Cost
Attribute
Status

Step 2:设置详细视图显示子网格
为了使用详细视图,请记得在页面头部引用视图脚本文件。
$(’#dg’).datagrid({
view: detailview,
detailFormatter:function(index,row){
return ’

’; }, onExpandRow: function(index,row){ var ddv = $(this).datagrid(’getRowDetail’,index).find(’table.ddv’); ddv.datagrid({ url:’datagrid22_getdetail.php?itemid=’+row.itemid, fitColumns:true, singleSelect:true, rownumbers:true, loadMsg:’’, height:’auto’, columns:[[ {field:’orderid’,title:’Order ID’,width:100}, {field:’quantity’,title:’Quantity’,width:100}, {field:’unitprice’,title:’Unit Price’,width:100} ]], onResize:function(){ $(’#dg’).datagrid(’fixDetailRowHeight’,index); }, onLoadSuccess:function(){ setTimeout(function(){ $(’#dg’).datagrid(’fixDetailRowHeight’,index); },0); } }); $(’#dg’).datagrid(’fixDetailRowHeight’,index); } });
当用户点击展开按钮(’+’)时,’onExpandRow’ 事件将被触发。 我们创建一个新的带有三列的子网格。 当子网格数据加载成功时或者改变尺寸大小时,请记得对主网格调用 ’fixDetailRowHeight’ 方法。
Step 3:服务器端代码
datagrid22_getdata.php
$result = array();

include ’conn.php’;

$rs = mysql_query(“select * from item where itemid in (select itemid from lineitem)“);

$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}

echo json_encode($items);

datagrid22_getdetail.php

include ’conn.php’;

$itemid = mysql_real_escape_string($_REQUEST[’itemid’]);

$rs = mysql_query(“select * from lineitem where itemid=’$itemid’“);
$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
echo json_encode($items);

jQuery Easyui实现左右布局


EasyUI
简介
easyui是一种基于jQuery的用户界面插件集合。
easyui为创建现代化,互动,JavaScript应用程序,提供必要的功能。
使用easyui你不需要写很多代码,你只需要通过编写一些简单HTML标记,就可以定义用户界面。
easyui是个完美支持HTML5网页的完整框架。
easyui节省您网页开发的时间和规模。
easyui很简单但功能强大的。
在后台管理系统开发的过程中,上左右的布局是最常见的页面布局方式,现在我们来看看使用easyui这个jquery前端框架如何快速搭建一个可用的页面框架。
1.在页面中引入easyui所需的文件
《%--
加载easyui的样式文件,bootstrap风格
--%》
《link
href=“${ctx
}/css/themes/bootstrap/easyui.css“
rel=“stylesheet“》
《link
href=“${ctx
}/css/themes/icon.css“
rel=“stylesheet“》
《%--
加载jquery和easyui的脚本文件
--%》
《script
src=“${ctx
}/js/jquery-easyui-../jquery.min.js“》《/script》
《script
src=“${ctx
}/js/jquery-easyui-../jquery.easyui.min.js“》《/script》
《script
src=“${ctx
}/js/jquery-easyui-../locale/easyui-lang-zh_CN.js“》《/script》
2.在页面body部分构建必要的html结构
《body》
《div
id=“home-layout“》
《!--
页面北部,页面标题
--》
《div
data-options=“region:’north’“
style=“height:50px;“》
《!--
add
your
code
--》
《/div》
《!--
页面西部,菜单
--》
《div
data-options=“region:’west’,title:’菜单栏’“
style=“width:200px;“》
《div
class=“home-west“》
《ul
id=“home-west-tree“》《/ul》
《/div》
《/div》
《!--
页面中部,主要内容
--》
《div
data-options=“region:’center’“》
《div
id=“home-tabs“》
《div
title=“首页“》
《h2
style=“text-align:
center“》欢迎登录《/h2》
《/div》
《/div》
《/div》
《/div》
《/body》
这里需要注意一点:easyui在使用layout布局的时候,north、south需要指定高度,west、east需要指定宽度,而center会自动适应高和宽。
3.使用js初始化easyui组件
我个人比较推荐使用js代码去初始化easyui组件,而不使用easyui标签中的data-options属性去初始化。因为对于后台开发人员来说,写js代码可能比写html标签更加熟悉,而且这样使得html代码更加简洁。
《script》
$(function(){
/*
*
初始化layout
*/
$(“#home-layout“).layout({
//使layout自适应容器
fit:
true
});
/*
*
获取左侧菜单树,并为其节点指定单击事件
*/
$(“#home-west-tree“).tree({
    //加载菜单的数据,必需
url:
“${ctx
}/pages/home-west-tree.json“,
method:
“get“,
    //是否有层次线
lines:
true,
    //菜单打开与关闭是否有动画效果
animate:
true,
    //菜单点击事件
onClick:
function(node){
if(node.attributes
&&
node.attributes.url){
         //打开内容区的tab,代码在其后
addTab({
url:
“${ctx
}/“
+
node.attributes.url,
title:
node.text
});
}
}
});
  /*
*
初始化内容区的tabs
*/
$(“#home-tabs“).tabs({
fit
:
true,
    //tab页是否有边框
border
:
false
});})
《/script》
《script》
/*
*
在内容区添加一个tab
*/
function
addTab(params){
var
t
=
$(“#home-tabs“);
var
url
=
params.url;
var
opts
=
{
title:
params.title,
closable:
true,
href:
url,
fit:
true,
border:
false
};
//如果被选中的节点对应的tab已经存在,则选中该tab并刷新内容
//否则打开一个新的tab
if(t.tabs(“exists“,
opts.title)){
var
tab
=
t.tabs(“select“,
opts.title).tabs(“getSelected“);
t.tabs(“update“,
{
tab:
tab,
options:
opts
});
}else{
t.tabs(“add“,
opts);
}
}
《/script》
4.easyui-tree组件所需的json格式
easyui使用的传输格式为json,它对json内容的格式有比较严格的限制,所以请注意查看api
[{
“text“:“区域管理“,
“attributes“:{
“url“:“pages/consume/area/areaList.jsp“
}
},{
“text“:“预约信息管理“,
“children“:[{
“text“:“商户预约信息查询“,
“attributes“:{
“url“:“/pages/consume/reservation/merchantReservation/merchantReservationList.jsp“
}
}]
},{
“text“:“准入申请管理“,
“children“:[{
“text“:“商户准入申请“,
“state“:“closed“,
“children“:[{
“text“:“商户待处理申请“,
“attributes“:{
“url“:“waterAply.do?method=toList&channelType=1&handleFlag=aply_wait“
}
},{
“text“:“商户审批中申请“,
“attributes“:{
“url“:“waterAply.do?method=toList&channelType=1&handleFlag=aply_current“
}
},{
“text“:“商户审批通过申请“,
“attributes“:{
“url“:“waterAply.do?method=toList&channelType=1&handleFlag=aply_pass“
}
},{
“text“:“商户被拒绝申请“,
“attributes“:{
“url“:“waterAply.do?method=toList&channelType=1&handleFlag=aply_refuse“
}
}]
}]
},{
“text“:“准入审批管理“,
“children“:[{
“text“:“商户审批管理“,
“state“:“closed“,
“children“:[{
“text“:“当前任务“,
“children“:[{
“text“:“商户当前初审任务“,
“attributes“:{
“url“:“pages/consume/approval/merchantApproval/merchantApprovalTrial.jsp“
}
},{
“text“:“商户当前复审任务“,
“attributes“:{
“url“:“pages/consume/approval/merchantApproval/merchantApprovalRetrial.jsp“
}
}]
},{
“text“:“商户已完成任务“,
“attributes“:{
“url“:“pages/consume/approval/merchantApproval/merchantApprovalDone.jsp“
}
},{
“text“:“商户不通过任务“,
“attributes“:{
“url“:“pages/consume/approval/merchantApproval/merchantApprovalRefuse.jsp“
}
}]
}]
}]
就这样,我们使用easyui完成了简单的左右布局。
以上所述是小编给大家分享的jQuery
Easyui实现上左右布局的相关内容,希望对大家有所帮助。

easyui如何移动DIV到指定位置


既然用了easyui那么就可以用jQuery的函数了,可以用offset函数设置匹配元素相对于document对象的坐标,也可以通过animate函数自己使用动画效果移动到指定位置