做人,生活,学习,玩....
第一步头部加载:
/js/jquery.js">
/css/flexigrid/flexigrid_gray.css" type="text/css">
/js/flexigrid.js">
/js/jquery.contextmenu.js" type="text/javascript">
/css/contextmenu.css" rel="stylesheet" type="text/css" />
第二步加载到页面
$().ready(function() {
var grid=$(".flex2").flexigrid
(
{
url: '/test/test.action',
dataType: 'json',
colModel : [
{display: '信息编号', name : 'id', width : 150, sortable : true, align: 'left'},
{display: '标题', name : 'title', width : 150, sortable : true, align: 'left'},
{display: '类别', name : 'sprivlege.name', width : 120, sortable : true, align: 'left'},
{display: '日期', name : 'datetime', width : 120, sortable : true, align: 'left'} ,
{display: '浏览次数', name : 'hit', width : 80, sortable : true, align: 'left'},
{display: '内容', name : 'content', width : 200, sortable : false,hide:true, align: 'left'}
],
buttons : [
{ name: '打印', displayname: '打印', bclass: 'print', onpress: toolbarItem },
{separator : true}, // 设置分割线
{ name: '增加', displayname: '增加', bclass: 'add', onpress: addItem },
{separator : true},
{ name: '删除', displayname: '删除', bclass: 'delete', onpress: deleteItem },
{separator : true} ,
{ name: '修改', displayname: '修改', bclass: 'edit', onpress: editItem },
{separator : true}
],
//searchitems : [
// {display: '标题', name : 'title', isdefault: true},
// {display: '类别', name : 'sprivlege.name'}
//],
usepager: true, // 是否用分页
title: '新闻列表', // 标题
pagestat: '显示 {from} ??到 {to} ??条 总共 {total} ??条', //显示当前页和总页面的样式
useRp: true, // 是否用每页显示多少行
rp: 20, // 默认每页显示的行数
showTableToggleBtn: true, // 是否显示按钮
rpOptions: [10,15,20,25,30,35,40],//可选择设定的每页结果数
procmsg: '正在查询,请稍等...',//正在处理的提示信息
onToggleCol: false, //当在行之间转换时
sortable: true, // 是否可排序
nomsg: '没有记录', // 没有记录的时的提示
// onChangeSort: true, //
sortname: "datetime",
onSubmit :addFormData,//数据提交时调用的自定义函数
checkbox:true,//是否要多选框
rowId:'id',//绑定行的id
rowbinddata: true,//配合rowhandler,如在双击事件中获取该行的数据
rowhandler: contextmenu,
//onSuccess:test,
sortorder: 'desc',
sortable: true,
width: 1000, // table的宽度
height: 600// table的高度
}
);
function contextmenu(row) {
// alert(row);
var menu = { width: 150, items: [
{ text: "查看", icon: "/images/icons/view.png", alias: "contextmenu-edit", action: contextMenuItem_click },
{ text: "修改", icon: "/images/icons/edit.png", alias: "contextmenu-view", action: contextMenuItem_click },
{ text: "删除", icon: "/images/icons/rowdelete.png", alias: "contextmenu-delete", action: contextMenuItem_click },
{ text: "刷新", icon: "/images/icons/table_refresh.png", alias: "contextmenu-reflash", action: contextMenuItem_click }
]
};
function contextMenuItem_click(target) {
var id = $(target).attr("id").substr(3);
var cmd = this.data.alias;
var ch = $.browser.msie ? target.ch : target.getAttribute("ch");
// var cell = ch.split("_FG$SP_");
if (cmd == "contextmenu-edit") {
editNews(id);
}
else if (cmd == "contextmenu-view") {
editNews(id);
}
else if (cmd == "contextmenu-delete") {
var name = cell[1];
if (confirm("你确认要删除新闻 [" + name + "] 吗?")) {
delNews(id);
}
}
else {
$("#flex2").flexReload();
}
}
$(row).contextmenu(menu);
}
function editItem(com,grid){
var selected_count = $('.trSelected', grid).length;
if (selected_count == 0) {
alert('请选择一条记录!');
return;
}
names = '';
if(selected_count>1){
alert('一次只能修改一条');
return;
}
//var data=new Array();
var ids;
//$('.trSelected td', grid).each(function(i) {
// data[i] = $(this).children('div').text();
// ids=i;
// });
$('.trSelected td:nth-child(2) div', grid).each(function(i) {
ids = $(this).text();
})
//salert(ids);
editNews(ids);
}
function editNews(ids){
$('#editForm').attr("action","/news/findNew s.action?news.id="+ids);
$('#editForm').submit();
}
function addItem(com,grid){
var selectedComs = document.getElementById("search.sprivlege.privid") ;
var kid=selectedComs.options[selectedComs.selectedInde x].value
$('#addForm').attr("action","/news/preAddNe ws.action");
$("[name=kid]").val(kid);
$('#addForm').submit();
}
function deleteItem(com,grid){
var selected_count = $('.trSelected', grid).length;
if (selected_count == 0) {
alert('请选择一条记录!');
return;
}
names = '';
$('.trSelected td:nth-child(3) div', grid).each(function(i) {
if (i)
names += ',';
names += $(this).text();
});
ids = '';
$('.trSelected td:nth-child(2) div', grid).each(function(i) {
if (i)
ids += ',';
ids += $(this).text();
})
if (confirm("确定删除新闻[" + names + "]?")) {
// alert(ids);
delNews(ids);
}
}
function delNews(ids){
$.ajax({
url : '/news/delete.action',
data : {
ids : ids
},
type : 'POST',
dataType : 'json',
success : function() {
$('#flex2').flexReload();//表格重载
}
});
}
function toolbarItem(com, grid) {
if (com=='打印'){
var name=new Array();
var ziduan=new Array();
var widths=new Array();
//alert($(".hDivBox ").html());
//alert($(".ftitle").html());
var title=$(".ftitle").html();
var i=0;
$(".hDivBox th").each(function(){
// alert($(this).text()+":"+$(this).attr("style"));
if($(this).attr("style")==undefined || $(this).attr("style")=="" || $(this).attr("style")=="display: table-cell;"){
name[i]=$(this).text();
ziduan[i]=$(this).attr("abbr")
widths[i]=$(this).width();
//alert($(this).width());
i++;
}
//alert($(this).text());
});
//alert(name);
// alert(ziduan);
// alert(widths);
// alert(title);
// alert(title);
$('#myform').attr("action","/report/report. action");
$("[name=heads]").val(name);
$("[name=alias]").val(ziduan);
$("[name=widths]").val(widths);
$("[name=title]").val(title);
$('#myform').submit();
}
}
function addFormData() {
var dt = $('#sform').serializeArray();
$("#flex2").flexOptions( {
params :dt
});
return true;
}
$('#sform').submit( function() {
$('#flex2').flexOptions( {
newp :1
}).flexReload();
return false;
});
});
function deletes(ids){
var id=ids.substring(3,ids.length);
//alert(id);
if (confirm("确定删除此新闻?")) {
$.ajax({
url : '/news/delete.action',
data : {
ids : id
},
type : 'POST',
dataType : 'json',
success : function() {
$('#flex2').flexReload();//表格重载
}
});
}
}
function modifypro(ids){
var id=ids.substring(3,ids.length);
$('#editForm').attr("action","/news/findNew s.action?news.id="+id);
$('#editForm').submit();
}
width="95%" border=0 cellPadding=0 cellSpacing=1 bgcolor="#CCCCCC" align="center">
width="20%" height="26" align="right">标题:
width="32%" valign="middle">????
新闻类别:
????
--新闻类别-
发表时间:
????" cssClass="text" οnclick='WdatePicker({dateFmt:"yyyy-MM-dd",qsEnabl ed:true,quickSel:["2000-10-01","%y-%M-01","%y-%M-%l d"]})' readOnly="true" size="12"/> 至 " οnclick='WdatePicker({dateFmt:"yyyy-MM-dd",qsEnabl ed:true,quickSel:["2000-10-01","%y-%M-01","%y-%M-%l d"]})'/>
是否推荐:
????
??????????????
flex2" class="flex2" align="left">
第一步头部加载:
/js/jquery.js">
/css/flexigrid/flexigrid_gray.css" type="text/css">
/js/flexigrid.js">
/js/jquery.contextmenu.js" type="text/javascript">
/css/contextmenu.css" rel="stylesheet" type="text/css" />
第二步加载到页面
$().ready(function() {
var grid=$(".flex2").flexigrid
(
{
url: '/test/test.action',
dataType: 'json',
colModel : [
{display: '信息编号', name : 'id', width : 150, sortable : true, align: 'left'},
{display: '标题', name : 'title', width : 150, sortable : true, align: 'left'},
{display: '类别', name : 'sprivlege.name', width : 120, sortable : true, align: 'left'},
{display: '日期', name : 'datetime', width : 120, sortable : true, align: 'left'} ,
{display: '浏览次数', name : 'hit', width : 80, sortable : true, align: 'left'},
{display: '内容', name : 'content', width : 200, sortable : false,hide:true, align: 'left'}
],
buttons : [
{ name: '打印', displayname: '打印', bclass: 'print', onpress: toolbarItem },
{separator : true}, // 设置分割线
{ name: '增加', displayname: '增加', bclass: 'add', onpress: addItem },
{separator : true},
{ name: '删除', displayname: '删除', bclass: 'delete', onpress: deleteItem },
{separator : true} ,
{ name: '修改', displayname: '修改', bclass: 'edit', onpress: editItem },
{separator : true}
],
//searchitems : [
// {display: '标题', name : 'title', isdefault: true},
// {display: '类别', name : 'sprivlege.name'}
//],
usepager: true, // 是否用分页
title: '新闻列表', // 标题
pagestat: '显示 {from} ??到 {to} ??条 总共 {total} ??条', //显示当前页和总页面的样式
useRp: true, // 是否用每页显示多少行
rp: 20, // 默认每页显示的行数
showTableToggleBtn: true, // 是否显示按钮
rpOptions: [10,15,20,25,30,35,40],//可选择设定的每页结果数
procmsg: '正在查询,请稍等...',//正在处理的提示信息
onToggleCol: false, //当在行之间转换时
sortable: true, // 是否可排序
nomsg: '没有记录', // 没有记录的时的提示
// onChangeSort: true, //
sortname: "datetime",
onSubmit :addFormData,//数据提交时调用的自定义函数
checkbox:true,//是否要多选框
rowId:'id',//绑定行的id
rowbinddata: true,//配合rowhandler,如在双击事件中获取该行的数据
rowhandler: contextmenu,
//onSuccess:test,
sortorder: 'desc',
sortable: true,
width: 1000, // table的宽度
height: 600// table的高度
}
);
function contextmenu(row) {
// alert(row);
var menu = { width: 150, items: [
{ text: "查看", icon: "/images/icons/view.png", alias: "contextmenu-edit", action: contextMenuItem_click },
{ text: "修改", icon: "/images/icons/edit.png", alias: "contextmenu-view", action: contextMenuItem_click },
{ text: "删除", icon: "/images/icons/rowdelete.png", alias: "contextmenu-delete", action: contextMenuItem_click },
{ text: "刷新", icon: "/images/icons/table_refresh.png", alias: "contextmenu-reflash", action: contextMenuItem_click }
]
};
function contextMenuItem_click(target) {
var id = $(target).attr("id").substr(3);
var cmd = this.data.alias;
var ch = $.browser.msie ? target.ch : target.getAttribute("ch");
// var cell = ch.split("_FG$SP_");
if (cmd == "contextmenu-edit") {
editNews(id);
}
else if (cmd == "contextmenu-view") {
editNews(id);
}
else if (cmd == "contextmenu-delete") {
var name = cell[1];
if (confirm("你确认要删除新闻 [" + name + "] 吗?")) {
delNews(id);
}
}
else {
$("#flex2").flexReload();
}
}
$(row).contextmenu(menu);
}
function editItem(com,grid){
var selected_count = $('.trSelected', grid).length;
if (selected_count == 0) {
alert('请选择一条记录!');
return;
}
names = '';
if(selected_count>1){
alert('一次只能修改一条');
return;
}
//var data=new Array();
var ids;
//$('.trSelected td', grid).each(function(i) {
// data[i] = $(this).children('div').text();
// ids=i;
// });
$('.trSelected td:nth-child(2) div', grid).each(function(i) {
ids = $(this).text();
})
//salert(ids);
editNews(ids);
}
function editNews(ids){
$('#editForm').attr("action","/news/findNew s.action?news.id="+ids);
$('#editForm').submit();
}
function addItem(com,grid){
var selectedComs = document.getElementById("search.sprivlege.privid") ;
var kid=selectedComs.options[selectedComs.selectedInde x].value
$('#addForm').attr("action","/news/preAddNe ws.action");
$("[name=kid]").val(kid);
$('#addForm').submit();
}
function deleteItem(com,grid){
var selected_count = $('.trSelected', grid).length;
if (selected_count == 0) {
alert('请选择一条记录!');
return;
}
names = '';
$('.trSelected td:nth-child(3) div', grid).each(function(i) {
if (i)
names += ',';
names += $(this).text();
});
ids = '';
$('.trSelected td:nth-child(2) div', grid).each(function(i) {
if (i)
ids += ',';
ids += $(this).text();
})
if (confirm("确定删除新闻[" + names + "]?")) {
// alert(ids);
delNews(ids);
}
}
function delNews(ids){
$.ajax({
url : '/news/delete.action',
data : {
ids : ids
},
type : 'POST',
dataType : 'json',
success : function() {
$('#flex2').flexReload();//表格重载
}
});
}
function toolbarItem(com, grid) {
if (com=='打印'){
var name=new Array();
var ziduan=new Array();
var widths=new Array();
//alert($(".hDivBox ").html());
//alert($(".ftitle").html());
var title=$(".ftitle").html();
var i=0;
$(".hDivBox th").each(function(){
// alert($(this).text()+":"+$(this).attr("style"));
if($(this).attr("style")==undefined || $(this).attr("style")=="" || $(this).attr("style")=="display: table-cell;"){
name[i]=$(this).text();
ziduan[i]=$(this).attr("abbr")
widths[i]=$(this).width();
//alert($(this).width());
i++;
}
//alert($(this).text());
});
//alert(name);
// alert(ziduan);
// alert(widths);
// alert(title);
// alert(title);
$('#myform').attr("action","/report/report. action");
$("[name=heads]").val(name);
$("[name=alias]").val(ziduan);
$("[name=widths]").val(widths);
$("[name=title]").val(title);
$('#myform').submit();
}
}
function addFormData() {
var dt = $('#sform').serializeArray();
$("#flex2").flexOptions( {
params :dt
});
return true;
}
$('#sform').submit( function() {
$('#flex2').flexOptions( {
newp :1
}).flexReload();
return false;
});
});
function deletes(ids){
var id=ids.substring(3,ids.length);
//alert(id);
if (confirm("确定删除此新闻?")) {
$.ajax({
url : '/news/delete.action',
data : {
ids : id
},
type : 'POST',
dataType : 'json',
success : function() {
$('#flex2').flexReload();//表格重载
}
});
}
}
function modifypro(ids){
var id=ids.substring(3,ids.length);
$('#editForm').attr("action","/news/findNew s.action?news.id="+id);
$('#editForm').submit();
}
width="95%" border=0 cellPadding=0 cellSpacing=1 bgcolor="#CCCCCC" align="center">
width="20%" height="26" align="right">标题:
width="32%" valign="middle">????
新闻类别:
????
--新闻类别-
发表时间:
????" cssClass="text" οnclick='WdatePicker({dateFmt:"yyyy-MM-dd",qsEnabl ed:true,quickSel:["2000-10-01","%y-%M-01","%y-%M-%l d"]})' readOnly="true" size="12"/> 至 " οnclick='WdatePicker({dateFmt:"yyyy-MM-dd",qsEnabl ed:true,quickSel:["2000-10-01","%y-%M-01","%y-%M-%l d"]})'/>
是否推荐:
????
??????????????
flex2" class="flex2" align="left">