jqgrid-调整大小和覆盖 [英] jqgrid - resize and overlay
问题描述
HTML
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquery Grid</title>
<link rel="stylesheet" type="text/css" href="themes/redmond/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" href="themes/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="themes/ui.multiselect.css" />
<script src="js/jquery-1.6.4.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.14.custom.min.js" type="text/javascript"></script>
<script src="js/jquery.layout.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="plugins/ui.multiselect.js" type="text/javascript"></script>
<script src="plugins/jquery.tablednd.js" type="text/javascript"></script>
<script src="plugins/jquery.contextmenu.js" type="text/javascript"></script>
<style>
.ui-jqgrid .ui-jqgrid-bdiv {
overflow: inherit !important;
}
.overlay{
position: absolute;
border: 1px solid black;
background-color: black;
color: #FFFFFF;
}
</style>
</head>
<body>
<table id="myjqgrid"></table>
<div id="Pager"></div>
</body>
</html>
JSON
{
"colModel": [
{
"name": "Overlay",
"label": "Overlay",
"width": 60,
"align": "left",
"jsonmap": "cells.0.value",
"sortable": true
},
{
"name": "ID",
"label": "ID",
"width": 60,
"align": "left",
"jsonmap": "cells.1.value",
"sortable": true
},
{
"name": "FirstName",
"label": "FirstName",
"width": 100,
"align": "left",
"jsonmap": "cells.2.value",
"sortable": false
},
{
"name": "LastName",
"label": "LastName",
"width": 100,
"align": "left",
"jsonmap": "cells.3.value",
"sortable": false
}
],
"colNames": [
"Overlay",
"ID",
"FirstName",
"LastName"
],
"mypage": {
"outerwrapper": {
"page":"1",
"total":"1",
"records":"20",
"innerwrapper": {
"rows":[
{
"id":"1",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"12345",
"label": "ID"
},
{
"value":"David",
"label": "FirstName"
},
{
"value":"Smith",
"label": "LastName"
}
]
},
{
"id":"2",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"37546",
"label": "ID"
},
{
"value":"Willy",
"label": "FirstName"
},
{
"value":"Peacock",
"label": "LastName"
}
]
},
{
"id":"3",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"62345",
"label": "ID"
},
{
"value":"Kim",
"label": "FirstName"
},
{
"value":"Holmes",
"label": "LastName"
}
]
},
{
"id":"4",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"186034",
"label": "ID"
},
{
"value":"Andy",
"label": "FirstName"
},
{
"value":"Wills",
"label": "LastName"
}
]
},
{
"id":"5",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"67345",
"label": "ID"
},
{
"value":"Paul",
"label": "FirstName"
},
{
"value":"Lawrence",
"label": "LastName"
}
]
},
{
"id":"6",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"12906",
"label": "ID"
},
{
"value":"Andy",
"label": "FirstName"
},
{
"value":"Charlery",
"label": "LastName"
}
]
},
{
"id":"7",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"564565",
"label": "ID"
},
{
"value":"Bets",
"label": "FirstName"
},
{
"value":"Josilyn",
"label": "LastName"
}
]
},
{
"id":"8",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"34345",
"label": "ID"
},
{
"value":"Pink",
"label": "FirstName"
},
{
"value":"Floyd",
"label": "LastName"
}
]
},
{
"id":"9",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"3429",
"label": "ID"
},
{
"value":"Rose",
"label": "FirstName"
},
{
"value":"Ben",
"label": "LastName"
}
]
},
{
"id":"10",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"6668",
"label": "ID"
},
{
"value":"Amy",
"label": "FirstName"
},
{
"value":"Wills",
"label": "LastName"
}
]
},
{
"id":"11",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"22786",
"label": "ID"
},
{
"value":"Zarine",
"label": "FirstName"
},
{
"value":"Khan",
"label": "LastName"
}
]
},
{
"id":"12",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"56444",
"label": "ID"
},
{
"value":"Dolly",
"label": "FirstName"
},
{
"value":"Mathews",
"label": "LastName"
}
]
},
{
"id":"13",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"99453",
"label": "ID"
},
{
"value":"Ginger",
"label": "FirstName"
},
{
"value":"Wills",
"label": "LastName"
}
]
},
{
"id":"14",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"1234",
"label": "ID"
},
{
"value":"Fabrice",
"label": "FirstName"
},
{
"value":"Papa",
"label": "LastName"
}
]
},
{
"id":"15",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"45000",
"label": "ID"
},
{
"value":"Helen",
"label": "FirstName"
},
{
"value":"Kites",
"label": "LastName"
}
]
},
{
"id":"16",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"1255",
"label": "ID"
},
{
"value":"Barbara",
"label": "FirstName"
},
{
"value":"Dorris",
"label": "LastName"
}
]
},
{
"id":"17",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"5555",
"label": "ID"
},
{
"value":"Eugene",
"label": "FirstName"
},
{
"value":"Mark",
"label": "LastName"
}
]
},
{
"id":"18",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"1867",
"label": "ID"
},
{
"value":"Harry",
"label": "FirstName"
},
{
"value":"King",
"label": "LastName"
}
]
},
{
"id":"19",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"45888",
"label": "ID"
},
{
"value":"Lorraine",
"label": "FirstName"
},
{
"value":"Williams",
"label": "LastName"
}
]
},
{
"id":"20",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"4567777",
"label": "ID"
},
{
"value":"Mark",
"label": "FirstName"
},
{
"value":"Sheppard",
"label": "LastName"
}
]
},
{
"id":"21",
"cells":
[
{
"value":"Click Me!",
"label": "Overlay"
},
{
"value":"7777",
"label": "ID"
},
{
"value":"Davis",
"label": "FirstName"
},
{
"value":"Sheppard",
"label": "LastName"
}
]
}
]
}
}
}
}
JQGrid定义
$(document).ready(function () {
$.ajax({
type: "GET",
url: "myjqgrid.json",
data: "",
dataType: "json",
success: function(response){
var columnData = response.mypage.outerwrapper,
columnNames = response.colNames,
columnModel = response.colModel;
$("#myjqgrid").jqGrid({
datatype: 'jsonstring',
datastr: columnData,
colNames: columnNames,
colModel: columnModel,
jsonReader: {
root: "innerwrapper.rows",
repeatitems: false
},
gridview: true,
pager: "#Pager",
rowNum: 21,
rowList: [21],
viewrecords: true,
recordpos: 'left',
multiboxonly: true,
multiselect: true,
sortname: 'ID',
sortorder: "desc",
sorttype: "text",
sortable: true,
caption: "<h2>MY JQGRID</h2>",
width: "1406",
height: "100%",
scrolloffset: 0,
loadonce: true,
cache: true,
loadComplete: function(){
$("td[title = 'Click Me!']").live("click", function(){
$("div.overlay").remove();
var RowID = $(this).closest("tr").attr("id");
if ($(this).siblings("div").length == 0) {
$(this).closest("td").append("<div class='overlay' id='"+RowID+"'>This is an overlay.</div>");
$(this).siblings("div#" + RowID).css("display", "block");
}
})
}
});
$("#myjqgrid").jqGrid('navGrid','#Pager', {add:false, edit:false, del:false, position: 'right'});
$("#myjqgrid").jqGrid('gridResize',{minWidth:800,maxWidth:1405,minHeight:350,maxHeight:680});
}
});
});
我遇到的问题
-
如果我不更改CSS,调整分格大小时分页效果很好
如果我将CSS从 .ui-jqgrid .ui-jqgrid-bdiv {overflow: auto;}
更改为 .ui-jqgrid .ui-jqgrid-bdiv {overflow: inherit !important;}
,分页栏在记录之间流动
我要更改CSS的原因是,当我单击"Click Me!"时,会显示一个覆盖图.链接在每一行的第二列.更改CSS可以正确显示页面上最后一条记录的覆盖图.如果我不更改CSS,则会隐藏页面上最后一条记录的覆盖.
the reason I am changing the CSS is because I have an overlay that is displayed when I click on "Click Me!" link in the second column of every row. Changing the CSS displays the overlay correctly for the last record on the page. If I don't change the CSS, the overlay for the last record on the page is hidden.
因此
我不更改CSS
- 我调整网格大小时分页效果很好
- 页面上最后一条记录的叠加层已隐藏
我更改CSS
-
调整网格大小时,在记录之间显示
- 分页栏
- 页面上最后一条记录的覆盖图正确显示
- pagination bar is displayed between the records when I resize the grid
- the overlay for the last records on the page is displayed correctly
我尝试将CSS定位和z-index用于叠加层,但无效.
推荐答案
如果我对您的理解正确,则需要执行以下操作
If I understand you correctly you need do something like the following
onCellSelect: function (rowid, iCol, cellcontent, e) {
$("#myoverlay").remove();
if (this.p.colModel[iCol].name === 'Overlay') { // iCol === 1
$('<div class="overlay" id="myoverlay">This is an overlay.</div>').css({
top: e.pageY,
left: e.pageX
}).appendTo('body');
}
}
代替loadComplete
中的代码.重要的是,上面的代码将div附加到<body>
而不是<td>
元素.只需按一下event
键即可将div放置在相应位置.
instead of the code in the loadComplete
. Important is that the code above append the div to <body>
instead of <td>
element. One can just use the event
of the click to place the div in the corresponding position.
在此处中查看演示.
您可以轻松地修改代码以使用div的内容,具体取决于rowid
,cellcontent
或任何其他条件.
You can easy modify the code to use the content of the div depend on the rowid
, cellcontent
or any other criteria.
顺便说一句.在使用的HTML代码中,应在<html>
之前使用<!DOCTYPE html ...
,并在<style>
中使用type="text/css"
属性. jqGrid没有cache: true
选项.
By the way. In the HTML code which you use you should use <!DOCTYPE html ...
before <html>
and use type="text/css"
attribute in the <style>
. jqGrid has no cache: true
option.
这篇关于jqgrid-调整大小和覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!