1. 数据分页及下载
mytable程序分页机制是:第一次请求,返回数据总数量,所有数据id,第一页数据
1.1. html模板
<table id=tb_main nopopmenu=0 class="tablesimpleline excel sort" style="width:100%;overflow-x:auto;" pagesize=10 pagecount=100>
<tbody name=title>
<tr class="ebsgray2">
<td nowrap=0 >代码</td>
<td nowrap=0 >名称</td>
<td nowrap=0 >分公司</td>
<td nowrap=0 >所属部门</td>
<td nowrap=0 >位置</td>
<td nowrap=0 >出库方式</td>
<td nowrap=0 >成本方式</td>
<td >操作</td>
</tr>
</tbody>
<tbody name=details>
<tr value="{wh_id}" onclick="loadpower(this)">
<td name=wh_code editable=0 mandatory=0 min-length=2 max-length=10>{wh_code}</td>
<td name=wh_caption editable=0 mandatory=0 min-length=2 max-length=50 >{wh_caption}</td>
<td readonly=0 name=bc_company editable=0 >{bc_company}</td>
<td readonly=0 name=dp_depart editable=0 >{dp_depart}</td>
<td name=wh_location editable=0 >{wh_location}</td>
<td readonly=0 name=wh_outstyle editable=0 type=int source="先进先出=0|后进先出=1" mandatory=0 align=center>{wh_outstyle}</td>
<td readonly=0 name=wh_feestyle editable=0 type=int source="移动平均=0|加权平均=1" mandatory=0 align=center>{wh_feestyle}</td>
<td readonly=0 align=center nowrap=0 class=fontfaint><span name="deletebtn" ><a onclick="delrec(this,'{wh_id}')" >删除</a></span></td>
</tr>
</tbody>
</table>
<div id=tb_main_pageinfo multi=1 class="info" style="padding-top:5px;padding-bottom:5px;padding-left:0px;padding-right:40px;width:100%;"></div>
1.2. 入口方法
mytable
function loadwarehouse()
{
mytable("tb_main","g_warehouse&key="+tohex($("#shopsearch").myval())) ;
}
1.3. 分页实现
create procedure [dbo].[mps_g_warehouse](
@cmpid int,
@branchid int,
@pagesize int ,
@pagecount int ,
@pageobjids varchar(8000),
@key nvarchar(50)--自己的定义查询参数,这些参数在点击第n页时,不会传递过来,所以逻辑处理时需要判断
)
as
begin
set nocount on
------------------------------通用代码------------------------------------
declare @amount int
select @amount = @pagecount*@pagesize
declare @dataIds table(objid int)
if @pageobjids!='_NONE' and @pageobjids!='_none_' and @pageobjids!=''
insert into @dataI ds(objid)
select value from dbo.fn_split_int(@pageobjids)
-------------------------------------------------------------------------
--查询第n页
if @pageobjids!='_NONE' and @pageobjids!='_none_' and @pageobjids!=''
begin
select a.* from mps_warehouse a, @dataIds
where wh_id=objid
order by objid
return
end
--第一次查询,需要返回三个结果集,cnt(总数),objid(所有参与分页的ID),*(第一页数据)
set @key = '%'+@key+'%'
select count(1) cnt from mps_warehouse
where wh_cmpid=@cmpid and
(
(wh_code like @key ) or
(wh_caption like @key) or
(wh_location like @key)
) and (@branchid=0 or wh_bcid=@branchid)
-- 查询所有ID
insert into @dataIds(objid)
select top(@amount) wh_id
from mps_warehouse
where wh_cmpid=@cmpid
and
(
(wh_code like @key ) or
(wh_caption like @key) or
(wh_location like @key)
)
and (@branchid=0 or wh_bcid=@branchid)
order by wh_bcid , wh_dpid , wh_code
-- 返回所有ID
select objid from @dataIds
order by objid
-- 返回第一页
select top(@pagesize) a.* ,
ISNULL(bc_company,'') bc_company ,
ISNULL(dp_depart,'') dp_depart
from mps_warehouse a
LEFT OUTER JOIN mps_depart On wh_dpid = dp_id and dp_cmpid=@cmpid
LEFT OUTER JOIN mps_groupbranch ON wh_bcid = bc_id and bc_cmpid=@cmpid
,@pobjs
where a.wh_id=objid
order by objid
set nocount off
end
1.4. 自定义数据下载功能
//以下载假期数据为例,下载数据
function downloadVacationOver(){
myconfirm("是否下载?",function() {
run4xml("g_emp_vacation_over_download",{excel:"0",mbcid:currentBcid},function(eof,ds,dsname){
if(!eof&&dsname=="t1" && $f[0]=="success"){
window.open("/api/excel?excelname="+$f[1])
}
});
});
}