- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此处使用的 jqGrid 版本:@license Guriddo jqGrid JS - v5.2.0 - 2016-11-27 版权所有(c) 2008,托尼·托莫夫,tony@trirand.com
下面的第一 block 代码是 jqGrid 的完整自包含实现。事实上,它主要取自 jqGrid 网站上的示例之一。我在其中添加了一个片段,即带有剪辑标记的注释行之间的部分。
添加的片段添加了自定义 editfunc。它工作得很好(在这个例子中,它当然或多或少是一个 stub ,只做一个警报)。此外,搜索可以使用其所有默认参数进行。对于两者,选择一行并单击相应的“编辑”或“搜索”图标。
<!DOCTYPE html>
<html lang="en">
<head>
<!-- The jQuery library is a prerequisite for all jqSuite products -->
<script type="text/ecmascript" src="./lib/jquery/jquery.min.js"></script>
<!-- This is the Javascript file of jqGrid -->
<script type="text/ecmascript" src="./lib/jqGrid-js-free/js/jquery.jqGrid.js"></script>
<!-- This is the localization file of the grid controlling messages, labels, etc.-->
<!-- We support more than 40 localizations -->
<script type="text/ecmascript" src="./lib/jqGrid-js-free/js/i18n/grid.locale-en.js"></script>
<!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
<link rel="stylesheet" type="text/css" media="screen" href="./lib/jquery-ui/jquery-ui.css" />
<!-- The link to the CSS that the grid needs -->
<link rel="stylesheet" type="text/css" media="screen" href="./lib/jqGrid-js-free/css/ui.jqgrid.css" />
<meta charset="utf-8" />
<title>jqGrid without PHP - Loading Data - JSON Live</title>
</head>
<body>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
<script type="text/javascript">
$(document).ready(function () {
$("#jqGrid").jqGrid({
colModel: [
{
label: 'Title',
name: 'Title',
width: 150,
formatter: formatTitle
},
{
label: 'Link',
name: 'Link',
width: 80,
formatter: formatLink
},
{
label: 'View Count',
name: 'ViewCount',
width: 35,
sorttype:'integer',
formatter: 'number',
align: 'right'
},
{
label: 'Answer Count',
name: 'AnswerCount',
width: 25
}
],
viewrecords: true, // show the current page, data rang and total records on the toolbar
width: 780,
height: 200,
rowNum: 15,
datatype: 'local',
pager: "#jqGridPager",
caption: "Load live data from stackoverflow"
});
fetchGridData();
function fetchGridData() {
var gridArrayData = [];
// show loading message
$("#jqGrid")[0].grid.beginReq();
$.ajax({
url: "http://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=jqgrid&site=stackoverflow",
success: function (result) {
for (var i = 0; i < result.items.length; i++) {
var item = result.items[i];
gridArrayData.push({
Title: item.title,
Link: item.link,
CreationDate: item.creation_date,
ViewCount: item.view_count,
AnswerCount: item.answer_count
});
}
// set the new data
$("#jqGrid").jqGrid('setGridParam', { data: gridArrayData});
// hide the show message
$("#jqGrid")[0].grid.endReq();
// refresh the grid
$("#jqGrid").trigger('reloadGrid');
}
});
}
function formatTitle(cellValue, options, rowObject) {
return cellValue.substring(0, 50) + "...";
};
function formatLink(cellValue, options, rowObject) {
return "<a href='" + cellValue + "'>" + cellValue.substring(0, 25) + "..." + "</a>";
};
/*---- 8< ------*/
// editfunc here works (an alert is popped up), although the format of the function parameters is not according to spec:
// searchfunc also works (it is the default)
$('#jqGrid').jqGrid( 'navGrid', '#jqGridPager',{
add:false, del:false, view:false,
editfunc: function(){alert('EDIT');}
});
/*---- >8 ------*/
});
</script>
</body>
</html>
现在获取相同的文件,删除剪断线之间的小片段,并将其替换为以下片段,这看起来更像是我需要实现的东西:
/*---- 8< ------*/
// editfunc does NOT work as desired here (no alert)
// search function works, WITH the parameters as specified here
// from the file jquery.jqGrid.js (): navGrid : function parameters: (elem, p, pEdit, pAdd, pDel, pSearch, pView)
// (=jqGrid-free @license Guriddo jqGrid JS - v5.2.0 - 2016-11-27 Copyright(c) 2008, Tony Tomov, tony@trirand.com)
$('#jqGrid').jqGrid( 'navGrid', '#jqGridPager',
{ add:false, del:false, view:false }, // p
{ editfunc: function(r){alert('EDIT');} }, // pEdit (does NOT work)
{ }, // pAdd
{ }, // pDel
{ multipleSearch: true, closeAfterSearch:true, closeOnEscape:true, searchOnEnter:true, showQuery:true }, // pSearch (works with these options)
{ } // pView
);
/*---- >8 ------*/
在这里,唉,editfunc 根本不起作用,我得到了默认的编辑功能。现在,搜索可以根据需要使用自定义指定参数进行工作。
简而言之:我似乎无法同时使用自定义的 editfunc 和具有自定义参数的搜索!
我看不出第二个片段有什么问题。顺便说一句。还可以引用 jqGrid wiki 上的一些示例。
任何让两者协同工作的提示将不胜感激。
最佳答案
问题很简单:您将 editfunc
放置在最后一个代码段中的错误位置。 editfunc
应指定为 navGrid
第二个参数的属性(与 add:false、del:false、view:false
一起) 。您在代码的第一部分中正确使用了 editfunc
,但将其放置在代码的第二部分中的错误位置。您可以通过使用来修复代码
$('#jqGrid').jqGrid( 'navGrid', '#jqGridPager',
{ add:false, del:false, view:false, editfunc: function(r){alert('EDIT');} }, // p
{ }, // pEdit
{ }, // pAdd
{ }, // pDel
{ multipleSearch: true, closeAfterSearch:true, closeOnEscape:true,
searchOnEnter:true, showQuery:true }, // pSearch (works with these options)
{ } // pView
);
顺便说一句,您将商业产品Guriddo jqGrid JS的代码放在jqGrid-js-free
目录中,这听起来很奇怪。 Guriddo jqGrid JS 不能免费使用。您可以查看当前价格here 。我开始开发free jqGrid jqGrid的fork,可以完全免费使用,正因为如此。免费的jqGrid实现了许多新功能,这对您会有帮助。演示https://jsfiddle.net/OlegKi/odvxefra/3/是对代码的一个小修改,显示
我另外使用了
url: "https://api.stackexchange.com/2.2/questions",
// add sending of custom parameters to the URL
postData: {
order: "desc",
sort: "activity",
tagged: "jqgrid",
site: "stackoverflow"
},
datatype: "json",
// below prmNames remove sending all standard jqGrid paranmeters
prmNames: {
page: null,
rows: null,
sort: null,
order: null,
search: null,
nd: null,
id: "question_id"
},
jsonReader: {
root: "items",
repeatitems: false,
id: "question_id"
},
loadonce: true,
forceClientSorting: true,
sortname: "creation_date",
sortorder: "desc"
数据将从同一 URL“http://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=jqgrid&site=stackoverflow ”加载,按 creation_date
属性按降序顺序在本地排序,并显示在网格中。通过在 additionalProperties
中添加属性,可以使用自定义格式化程序中的其他属性。例如,您可以添加 additionalProperties: ["owner", "is_answered", "score", "last_activity_date"]
以在本地保存属性并有权访问自定义属性等内部的属性格式化程序。
关于javascript - 指定自定义搜索参数时,jqGrid 自定义 editfunc 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41080215/
我的 jqgrid 中有一个状态栏。 如果状态为事件,我希望同一行中的另一个单元格为绿色。如果状态为“未激活”,我希望单元格为红色。 如何做到这一点? 截至目前,我已经在“图像”行上创建了一个自定义格
我正在使用 jqgrid 显示服务器中存在的数据如何在鼠标悬停工具提示上显示数据描述。 这是在 jqgrid 上显示工具提示的最佳方式? 最佳答案 鼠标悬停时 jqGrid 中显示的工具提示只不过是相
我有一个 asp.net 项目,它使用 jqgrid 作为 javascript 网格。如何找出正在使用的 jqgrid 版本? 最佳答案 如果您需要以编程方式查询版本,您可以使用: $.jgrid.
有没有办法以编程方式(在 Javascript 中,而不是服务器端)过滤当前显示在 jqGrid 中的数据?所有搜索示例似乎都依赖于使用 jqGrid 自己的搜索 UI,这对我不起作用。例如,我希望能
有没有一种方法可以切换网格的multiselect选项? 如果在创建网格时multiselect不是multiselect,则更改网格的TRUE参数并要求重新加载具有禁用或不创建标题列时将标题留在后面
我在jqGrid中使用列重新排序功能 $grid = jQuery("#list").jqGrid({ sortable:true, ... }); 重新排列列后是否会触发事件?如果有
我正在构建我的第一个ASP.NET MVC 3应用程序并使用jqGrid。我的其中一个列“Flavor Created”是日期列,我想使用DatePicker过滤该列上的网格。当前发生的情况是:用户单
我试图基于选定的行启用导航。因此,用户从jQgrid中选择一行,然后按show(有一个显示网格的按钮,我看到了edit,add等),它需要根据url转到新页面(该行的一部分) )。 $(documen
有没有办法设置 jqgrid 列的固定宽度(最大和最小)? 我已经在 colmodel 中设置了宽度属性,但是如果我调整网格的大小,列正在调整。 最佳答案 不能定义列的最大和最小宽度,但可以使其具有固
我被困在这里-生产前要做的最后一件事。 来自oracle的日期采用以下格式:“ 8/14/2012 10:46:48 AM” 我在jqgrid上使用以下内容: { name: 'CreationDat
我是 jqGrid 的新手,谁能解释一下 jqgrid colModel 中 Index 属性的用途 最佳答案 如果您使用datatype: "json" 或datatype: "xml" 没有额外使
我正在学习 jqGrid,希望最终能将它连接到 Redis 数据库。作为第一步,我正在处理本地数据。这是我必须使用可排序行(在网格中拖放行)。网格出现并且看起来不错,列甚至可以排序,但我无法选择一行并
我想每 5 分钟重新加载一次 jqgrid(给定间隔时间),是否有任何选项/事件。如何做到这一点? 最佳答案 您可以使用setInterval JavaScript函数进行自动刷新 var grid
我正在学习 jqGrid,希望最终能将它连接到 Redis 数据库。作为第一步,我正在处理本地数据。这是我必须使用可排序行(在网格中拖放行)。网格出现并且看起来不错,列甚至可以排序,但我无法选择一行并
大家好,我正在使用 JQ Grid,我得到的日期格式是 2012-09-16T00:00:00,就像这样。我希望日期格式采用 2012-09-16 方式。我试图改变它,但它不起作用。请查看我的代码并告
当我搜索 JQGrid 使用的图标时,我找到了包含所有图标的单个 PNG 文件。我想知道它如何使用图像的一部分作为 JQGrid 中使用的按钮的图标。 最佳答案 jqGrid 使用来自 jQuery
我使用 loadonce 预先获取所有数据,然后在本地进行排序和过滤。 我的列值之一是一个对象数组。在 colModel 选项中,我使用了如下所示的格式化程序函数: function my_forma
我想要在 jqGrid 中右键单击列标题时的列名称。任何代码将不胜感激。 最佳答案 可以绑定(bind)contextmenu事件到所有列标题。每个标题都是 元素等它的 DOM 支持 cellInde
我想计算总计 无需在 calctotal.php 中执行即可即时完成。从本质上讲,这是一个计算列。我想使用一些事件,如 afterInsertRow ,但即使没有事件,它也会将列数据移动一格,因为 X
我有一些数据想在 jqqgrid 中显示。除了添加、编辑和删除之外,还可以对选定记录执行其他操作。我喜欢在该记录的行中有一个用于该操作的按钮/链接的流程。有没有办法在 jqgrid 中添加未绑定(bi
我是一名优秀的程序员,十分优秀!