我自己下了个插件
没咋写过
调用代码:$.pageInfo.getPageInfo({
divId: "divPageInfo", //填充分页信息的标签Id
url: "../BaseInfoManage/GetBaseInfoByPage", //ajax发送请求的地址
queryParams: "",
type: "POST", //ajax请求方式
async: true, //ajax是否异步请求
loadMsg: "loading...", //加载信息显示内容
columns: [[ //显示列 field绑定名称,cfield绑定列名称,title显示标题,width宽度,align对齐方式
{field: 'piName', cfield: 'pi_name', title: '姓名', width: 200, align: 'left' },
{ field: 'ciName', cfield: 'ci_name', title: '单位', width: 200, align: 'left' },
{ field: 'piCreateTime', cfield: 'pi_create_time', title: '创建时间', width: 200, align: 'left' },
{ field: '', title: '操作', width: 200, align: 'left', formatter:
function (info) {
var con = "<a href=\"#\" id=\"" + info.piId + "\" class=\"line\">删除</a>"; ;
return con;
}
}//field: ''为自定义单元格,
]],
pageIndex: "1", //默认页数
pageSize: "12", //默认记录数
sortName: 'pi_create_time', //排序列名
sortOrder: 'desc'//asc(升序)或desc(降序)
});
其中
{ field: '', title: '操作', width: 200, align: 'left', formatter:
function (info) {
var con = "<a href=\"#\" id=\"" + info.piId + "\" class=\"line\">删除</a>"; ;
return con;
}
}我用json取出
function (info) {
var con = "<a href=\"#\" id=\"" + info.piId + "\" class=\"line\">删除</a>"; ;
return con;
}怎么给这个函数传参并得到结果...
请jquery大虾赐教
没咋写过
调用代码:$.pageInfo.getPageInfo({
divId: "divPageInfo", //填充分页信息的标签Id
url: "../BaseInfoManage/GetBaseInfoByPage", //ajax发送请求的地址
queryParams: "",
type: "POST", //ajax请求方式
async: true, //ajax是否异步请求
loadMsg: "loading...", //加载信息显示内容
columns: [[ //显示列 field绑定名称,cfield绑定列名称,title显示标题,width宽度,align对齐方式
{field: 'piName', cfield: 'pi_name', title: '姓名', width: 200, align: 'left' },
{ field: 'ciName', cfield: 'ci_name', title: '单位', width: 200, align: 'left' },
{ field: 'piCreateTime', cfield: 'pi_create_time', title: '创建时间', width: 200, align: 'left' },
{ field: '', title: '操作', width: 200, align: 'left', formatter:
function (info) {
var con = "<a href=\"#\" id=\"" + info.piId + "\" class=\"line\">删除</a>"; ;
return con;
}
}//field: ''为自定义单元格,
]],
pageIndex: "1", //默认页数
pageSize: "12", //默认记录数
sortName: 'pi_create_time', //排序列名
sortOrder: 'desc'//asc(升序)或desc(降序)
});
其中
{ field: '', title: '操作', width: 200, align: 'left', formatter:
function (info) {
var con = "<a href=\"#\" id=\"" + info.piId + "\" class=\"line\">删除</a>"; ;
return con;
}
}我用json取出
function (info) {
var con = "<a href=\"#\" id=\"" + info.piId + "\" class=\"line\">删除</a>"; ;
return con;
}怎么给这个函数传参并得到结果...
请jquery大虾赐教
解决方案 »
- 请教firefox的js兼容性问题
- 闲来无事,试验页面采用拖放进行传递数据的通用方法
- 单行文本即时显示数据读取的行数~~急!!
- 推荐一个极好的WEB报表控件ATGrid,能在线看到效果
- 如何用WEB里的BUTTON调用桌面的一个EXE的快捷方式
- 拆串问题请教
- 想要一个效果,某页面上按钮为添加,点下去打开新窗口,数据添加完毕按完成,成功则关闭新窗口,弹出窗口得页面会自动刷新下
- 求救高手!在线等,急急急...
- 求教:在子窗体如何给父窗体里的某个桢里的输入域付值?
- html与java后台通过ajax交互 没反应不能正常调用
- Javascript初学者问下onSubmit="hello()"为什么不执行呢?
- js替换字符问题:将搜索结果高亮或红色字体显示。
$.extend({
WebGrid: function(strid, config) {
var grid = this;
var pagecount = 1;
var rowcount = 0;
var content = $("#" + strid);
var headerheight = 25;
var pagerheight = 25;
var contentwidth = content.attr("clientWidth");
var tableheight;
var scrollLeft;
var scrollTop; var cookie = function(key, value) {
if (arguments.length == 1) {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
if ($.trim(cookies[i].split("=")[0]) == key) {
return unescape($.trim(cookies[i].split("=")[1]));
}
}
return null;
}
else {
document.cookie = key + "=" + escape(value);
}
};
//阻止事件冒泡
var stopBubble = function(e){
if (e && e.stopPropagation){
e.stopPropagation();
}
else{
event.cancelBubble = true;
}
}; var createHeader = function(c) {
var tablewidth = (function() {
var width = 0;
for (var i = 0; i < c.columns.length; i++) {
width += c.columns[i].width;
}
if (c.showCheckBox){
return width + 27;
}
return width;
})();
var arr = [];
arr.push("<table id='" + strid + "_table_header' cellspacing='0' width='" + tablewidth + "px' style='background-color:Gray;table-layout:fixed;border-collapse:collapse;height:" + headerheight + "px;'><tr style='cursor:default;'>");
if (c.showCheckBox){
arr.push("<td field='' style='width:25px;border:solid 1px " + c.style.borderColor + ";border-left:none;border-top:none;border-bottom:none;background-color:" + c.style.headerBgColor + ";text-align:center;font-weight:bold;'><input id='" + strid + "_checkall' type='checkbox'/></td>");
}
for (var i = 0; i < c.columns.length; i++) {
var field = c.columns[i].field ? c.columns[i].field : "";
var title = c.sortable ? c.columns[i].type.toLowerCase() == "data" ? " title='单击进行排序' " : "" : "";
var borderleft = c.showCheckBox ? "" : i == 0 ? "border-left:none;" : "";
var display = c.columns[i].visible ? "" : "display:none;";
var arrow = c.sortable ? c.columns[i].field == c.sortName ? c.sortOrder == "" ? " " : c.sortOrder.toLowerCase() == "asc" ? "↑" : "↓" : " " : " ";
arr.push("<td field='" + field + "' order='" + c.sortOrder + "' width='" + c.columns[i].width + "px' " + title + " style='border:solid 1px " + c.style.borderColor + ";" + borderleft + display + "border-top:none;border-bottom:none;background-color:" + c.style.headerBgColor + ";text-align:center;font-weight:bold;'><span>" + c.columns[i].title + "</span><span style='color:Black;font-size:18px;'>" + arrow + "</span></td>");
}
arr.push("</tr></table>");
return arr.join("");
}; var createBody = function(c) {
if (c) {
c.params = c.params ? c.params : {};
if (c.pager) {
if (c.sortable) {
c.params.pageIndex = c.pageIndex;
c.params.pageSize = c.pageSize;
c.params.sortName = c.sortName;
c.params.sortOrder = c.sortOrder;
}
else {
c.params.pageIndex = c.pageIndex;
c.params.pageSize = c.pageSize;
}
}
else {
if (c.sortable) {
c.params.sortName = c.sortName;
c.params.sortOrder = c.sortOrder;
}
} $.ajax({
url: c.url,
async: false,
type: "post",
data: c.params,
dataType: "text",
success: function(txt) {
var obj = { DataTable: [], RowCount: 0 };
try {
obj = eval("(" + txt + ")");
}
catch(e){
}
rowcount = obj.RowCount;
pagecount = parseInt(rowcount % c.pageSize == 0 ? (rowcount / c.pageSize > 0 ? rowcount / c.pageSize : 1) : rowcount / c.pageSize + 1);
c.pageIndex = c.pageIndex > pagecount ? pagecount : c.pageIndex;
grid.dataRows = obj.DataTable;
},
error: function(e) {
}
});
} var rows = grid.dataRows;
var tablewidth = (function() {
var width = 0;
for (var i = 0; i < c.columns.length; i++) {
width += c.columns[i].width;
}
if (c.showCheckBox){
return width + 27;
}
return width;
})(); var arr = [];
if (rows.length > 0){
arr.push("<table id='" + strid + "_table_body' cellspacing='0' width='" + tablewidth + "px' style='border:solid 1px " + c.style.borderColor + ";border:none;table-layout:fixed;border-collapse:collapse;'>");
for (var i = 0; i < rows.length; i++) {
arr.push("<tr style='background-color:" + c.style.bodyBgColor + "'>");
if (c.showCheckBox){
arr.push("<td style='width:25px;brder-top:none;border-left:none;border-bottom:dashed 1px " + c.style.borderColor + ";border-right:dashed 1px " + c.style.borderColor + ";text-align:center;'><input class='" + strid + "_checkone' type='checkbox'/></td>");
}
for (var j = 0; j < c.columns.length; j++) {
var title = "";
var str = " ";
var display = c.columns[j].visible ? "" : "display:none;";
switch (c.columns[j].type.toLowerCase()) {
case "data":
var val = rows[i][c.columns[j].field] ? rows[i][c.columns[j].field].replace(/</g, "<").replace(/>/g, ">") : "";
var txt = val == "" ? c.columns[j].defaultVal == "" ? " " : c.columns[j].defaultVal : c.columns[j].format(val);
str = "<p style='text-overflow:ellipsis;white-space: nowrap;'>" + txt + "</p>";
title = " title='" + rows[i][c.columns[j].field] + "' ";
break;
case "button":
str = "<input class='" + strid + "_grid_action_" + j + "' type='button' value='" + c.columns[j].text + "'/>";
break;
case "linkbutton":
str = "<a class='" + strid + "_grid_action_" + j + "' href='javascript:'>" + c.columns[j].text + "</a>";
break;
default:
break;
}
arr.push("<td " + title + " width='" + c.columns[j].width + "px' height='" + c.columns[j].height + "px' style='brder-top:none;border-left:none;border-bottom:dashed 1px " + c.style.borderColor + ";border-right:dashed 1px " + c.style.borderColor + ";text-align:" + c.columns[j].align + ";" + display + "'>" + str + "</td>");
}
arr.push("</tr>");
}
arr.push("</table>");
}
else{
arr.push("<table id='" + strid + "_table_body' width='" + tablewidth + "px' cellspacing='0' border='0' style='table-layout:fixed;border:none;'><tr>");
if (c.showCheckBox){
arr.push("<td style='width:26px;table-layout:fixed;border:none;'></td>");
}
for (var i = 0; i < c.columns.length; i++) {
arr.push("<td style='width:" + (c.columns[i].width + 1) + "px;border:none;'></td>");
}
arr.push("</tr></table>");
}
return arr.join("");
};
var arr = [];
var show = c.showPagerInfo ? "" : "display:none;";
arr.push("<div style='margin-top:0px;margin-left:4px;float:left;'>");
arr.push("<a id='" + strid + "_grid_afirst' href='javascript:' style='color:Black;text-decoration:none;'>首页</a> ");
arr.push("<a id='" + strid + "_grid_aprevious' href='javascript:' style='color:Black;text-decoration:none;'>上页</a> ");
arr.push("<input id='" + strid + "_grid_pageindex' type='text' style='width:30px;height:15px;font-size:11px;' value='" + c.pageIndex + "'/> ");
arr.push("<a id='" + strid + "_grid_anext' href='javascript:' style='color:Black;text-decoration:none;'>下页</a> ");
arr.push("<a id='" + strid + "_grid_alast' href='javascript:' style='color:Black;text-decoration:none;'>尾页</a>");
arr.push("</div><div style='margin-top:4px;float:right;margin-right:4px;" + show + "'>");
arr.push("共 <span style='color:black' id='" + strid + "_grid_spanRow'></span> 条,");
arr.push("每页 <span style='color:black' id='" + strid + "_grid_spanSize'></span> 条,");
arr.push("共 <span style='color:black' id='" + strid + "_grid_spanCount'></span> 页,");
arr.push("第 <span style='color:black' id='" + strid + "_grid_spanIndex'></span> 页</div>");
return arr.join("");
}; this.dataRows = [];
this.currentRowIndex = -1;
this.config = (function(c) {
if (!c || !c.url || !c.columns || c.columns.constructor != Array) {
return null;
}
c.pager = c.pager == null ? true : c.pager;
c.showPagerInfo = c.showPagerInfo == null ? true : c.showPagerInfo;
c.params = c.params ? c.params : {};
c.idField = c.idField ? c.idField : "";
c.pageIndex = cookie(strid + "_pageindex") ? cookie(strid + "_pageindex") : c.pageIndex ? c.pageIndex : 1;
c.pageSize = c.pageSize ? c.pageSize : 10;
c.sortable = c.sortable == null ? false : c.sortable;
c.sortName = c.sortName ? c.sortName : "";
c.sortOrder = c.sortOrder ? c.sortOrder : "asc";
c.fontSize = c.fontSize ? c.fontSize : 13;
c.multiSelect = c.multiSelect == null ? true : c.multiSelect;
c.isCookie = c.isCookie == null ? true : c.isCookie;
c.showCheckBox = c.showCheckBox == null ? false : c.showCheckBox;
c.afterLoaded = c.afterLoaded ? c.afterLoaded : function(){};
c.style = c.style ? c.style : {};
c.style.borderColor = c.style.borderColor ? c.style.borderColor : "Gray";
c.style.headerBgColor = c.style.headerBgColor ? c.style.headerBgColor : "#D4D0C8";
c.style.bodyBgColor = c.style.bodyBgColor ? c.style.bodyBgColor : "White";
c.style.pagerBgColor = c.style.pagerBgColor ? c.style.pagerBgColor : "#D4D0C8";
c.style.scrollbarColor = c.style.scrollbarColor ? c.style.scrollbarColor : "#D4D0C8";
c.style.selectedRowColor = c.style.selectedRowColor ? c.style.selectedRowColor : "#D4D0C8";
c.style.rowHighLightColor = c.style.rowHighLightColor ? c.style.rowHighLightColor : "#D4D0C8"; for (var i = 0; i < c.columns.length; i++) {
var col = c.columns[i];
col.type = col.type ? col.type : "data";
col.title = col.title ? col.title == "" ? " " : col.title : " ";
col.text = col.text ? col.text == "" ? " " : col.text : " ";
col.visible = col.visible == null ? true : col.visible;
col.align = col.align ? col.align : "left";
col.width = col.width ? col.width : 150;
col.height = col.height ? col.height : 15;
col.defaultVal = col.defaultVal ? col.defaultVal : "";
col.format = col.format ? col.format : function(str) { return str; };
} tableheight = config.pager ? content.attr("clientHeight") - headerheight - pagerheight - 5: content.attr("clientHeight") - headerheight - 3;
return c;
})(config);
//获取分页信息
this.getPagerInfo = function(){
var c = grid.config;
obj = { rowCount: rowcount };
if (c.pager){
obj.pageIndex = c.pageIndex;
obj.pageSize = c.pageSize;
obj.pageCount = pagecount;
}
return obj;
};
//获取选中行的数据
this.selectedRows = function(){
var arr = [];
var rows = grid.selectedRowsEx();
for(var i=0; i< rows.length; i++){
arr.push(rows[i].data);
}
return arr;
};
//获取选中行的索引及数据
this.selectedRowsEx = function(){
var c = grid.config;
var arr = [];
var TRs = $("#" + strid + " #" + strid + "_table_body").find("tr");
for(var i=0; i < TRs.length; i++){
if (TRs[i].selected == "1"){
arr.push({ index: i, data: grid.dataRows[i] });
}
}
return arr;
};
//下页
this.nextPage = function(){
grid.gotoPage(grid.config.pageIndex + 1);
};
//上页
this.prePage = function(){
grid.gotoPage(grid.config.pageIndex - 1);
};
//页数
this.gotoPage = function(index){
var c = grid.config;
if (c.pager){
index = parseInt(index);
if (!isNaN(index)){
if (index < 1){
c.pageIndex = 1;
}
else if (index > pagecount){
c.pageIndex = pagecount;
}
else{
c.pageIndex = index;
}
}
if (c.isCookie){
cookie(strid + "_pageindex", c.pageIndex);
}
grid.load();
}
};
var config = grid.config;
var tempColor;
(function(c) {
content.css({ "font-size": c.fontSize + "px" }).empty(); //表头
var header = $("<div style='text-align:left;background-color:" + c.style.headerBgColor + ";border:solid 1px " + c.style.borderColor + ";overflow:hidden;width:" + contentwidth + "px;height:" + headerheight + "px;'></div>").appendTo(content);
//表数据
var body = $("<div id='" + strid + "_div_body' style='text-align:left;scrollbar-base-color:" + c.style.scrollbarColor + ";border:solid 1px " + c.style.borderColor + ";border-top:none;overflow:auto;width:" + contentwidth + "px;height:" + tableheight + "px;'></div>").appendTo(content);
//分页
var pager;
if (c.pager){
pager = $("<div style='background-color:" + c.style.pagerBgColor + ";border:solid 1px " + c.style.borderColor + ";border-top:none;overflow:hidden;width:" + contentwidth + "px;height:" + pagerheight + "px;'></div>").appendTo(content);
}
//表数据
body.append(createBody(c));
var table_body = $("#" + strid + " #" + strid + "_table_body");
var div_body = $("#" + strid + " #" + strid + "_div_body");
var tbRows = $("tr", table_body); //表头
var flag = table_body.attr("clientHeight") <= div_body.attr("clientHeight");
var width = flag ? contentwidth : contentwidth - 17;
var border_right_width = flag ? 0 : 1;
header.append("<div id='" + strid + "_div_header' style='border-right:solid " + border_right_width + "px " + c.style.borderColor + ";overflow:hidden;width:" + width + "px;height:" + headerheight + "px;'>" + createHeader(c) + "</div>");
var div_header = $("#" + strid + " #" + strid + "_div_header"); //分页
if (c.pager){
pager.append(createPager(c));
}
var grid_afirst = $("#" + strid + " #" + strid + "_grid_afirst");
var grid_aprevious = $("#" + strid + " #" + strid + "_grid_aprevious");
var grid_pageindex = $("#" + strid + " #" + strid + "_grid_pageindex");
var grid_anext = $("#" + strid + " #" + strid + "_grid_anext");
var grid_alast = $("#" + strid + " #" + strid + "_grid_alast");
var grid_spanRow = $("#" + strid + " #" + strid + "_grid_spanRow");
var grid_spanSize = $("#" + strid + " #" + strid + "_grid_spanSize");
var grid_spanCount = $("#" + strid + " #" + strid + "_grid_spanCount");
var grid_spanIndex = $("#" + strid + " #" + strid + "_grid_spanIndex");
var checkall = $("#" + strid + " #" + strid + "_checkall");
var checkone = $("#" + strid + " ." + strid + "_checkone");
var table_body = $("#" + strid + " #" + strid + "_table_body");
var table_header = $("#" + strid + " #" + strid + "_table_header");
//设置分页
var setpager = function(index, count, size) {
if (index <= 1) {
grid_afirst.attr({ "disabled": true });
grid_afirst.css({ "color": "Black", "text-decoration": "none" });
grid_afirst.removeAttr("href");
grid_aprevious.attr({ "disabled": true });
grid_aprevious.css({ "color": "Black", "text-decoration": "none" });
grid_aprevious.removeAttr("href");
}
else {
grid_afirst.attr({ "disabled": false, "href": "javascript:" });
grid_aprevious.attr({ "disabled": false, "href": "javascript:" });
} if (index >= pagecount) {
grid_anext.attr({ "disabled": true });
grid_anext.css({ "color": "Black", "text-decoration": "none" });
grid_anext.removeAttr("href");
grid_alast.attr({ "disabled": true });
grid_alast.css({ "color": "Black", "text-decoration": "none" });
grid_alast.removeAttr("href");
}
else {
grid_anext.attr({ "disabled": false, "href": "javascript:" });
grid_alast.attr({ "disabled": false, "href": "javascript:" });
} grid_pageindex.val(index);
grid_spanRow.text(rowcount);
grid_spanSize.text(size);
grid_spanCount.text(count);
grid_spanIndex.text(index);
}; setpager(c.pageIndex, pagecount, c.pageSize);
div_body.scrollLeft(scrollLeft);
div_body.scrollTop(scrollTop);
div_header.scrollLeft(scrollLeft);
grid.currentRowIndex = -1;
if (c.afterLoaded && c.afterLoaded.constructor == Function){
c.afterLoaded();
}
//滚动事件
div_body.scroll(function() {
var left = $(this).scrollLeft();
var top = $(this).scrollTop();
div_header.scrollLeft(left);
scrollLeft = left;
scrollTop = top;
});
//首页
grid_afirst.click(function() {
if (!$(this).attr("disabled") || $(this).attr("disabled") == "false") {
grid.gotoPage(1);
}
}); //上页
grid_aprevious.click(function() {
if (!$(this).attr("disabled") || $(this).attr("disabled") == "false") {
grid.prePage();
}
});
//页数
grid_pageindex.keydown(function(e) {
if (e.keyCode == 13) {
grid.gotoPage($(this).val());
}
}); //下页
grid_anext.click(function() {
if (!$(this).attr("disabled") || $(this).attr("disabled") == "false") {
grid.nextPage();
}
}); //尾页
grid_alast.click(function() {
if (!$(this).attr("disabled") || $(this).attr("disabled") == "false") {
grid.gotoPage(pagecount);
}
});
//全选全不选
checkall.click(function(){
if (c.multiSelect){
checkone.attr({ "checked": $(this).attr("checked") });
table_body.find("tr").attr({ "selected": $(this).attr("checked") ? "1" : "0" });
}
else{
$(this).attr("checked",false);
}
});
//单选
checkone.click(function(){
var color = this.checked ? c.style.selectedRowColor : c.style.bodyBgColor;
var selected = this.checked ? "1" : "0";
if (c.multiSelect){
$(this).parent().parent().css({ "background-color": color });
}
else{
checkone.attr("checked",false);
$(this).attr("checked",true);
table_body.find("tr").css({ "background-color": c.style.bodyBgColor });
$(this).parent().parent().css({ "background-color": color });
}
});
_columns_formatter_Page[i] = column.formatter;
_columns_formatter_Page[j](info)
谢谢各位...问题以解决..不是传参获取结果的问题
是我把逻辑写错了
...