如何添加自定義錯誤消息顯示在jqgrid表中如果沒有數據或數據沒有找到 是否有可能呢?Jqgrid如何添加自定義錯誤來顯示在表
這裏是我的代碼的打擊和屏幕抓取
代碼
<script type="text/ecmascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.1/js/jquery.jqgrid.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
$(document).ready(function() {
var mydata;
var collateralid= getQueryUrlString("id");
console.log(collateralid);
$(".monitoring-red").jqGrid({
url:"json/data-"+collateralid.trim()+".json",
data: mydata,
datatype: "json",
emptyrecords: "0 records found",
postData: {
json: JSON.stringify(mydata)
},
success: function(mydata, textStatus, jqXHR) {
console.log(" data :" +mydata);
},
colModel: [
{ name: 'ClientID', label: 'ClientId',width: 70, key: true,
formatter: "showlink",
formatoptions: {
baseLinkUrl: testUrl,
idName: "",
addParam: function (options) {
return "clientid="+options.rowid+"-20160408" ;
}
}
},
{ name: 'Borrower',label: 'Borrower', align:'right', width: 115 },
{ name: 'Brokerage',label: 'Brokeage', align:'right', width: 125 },
{ name: 'LoanBalance', label: 'Loan Balance',align:'right',width: 100, formatter: 'currency',
formatoptions: { prefix: "$", suffix: " "}},
/*{ label: 'Value1',
name: 'Value1',
width: 80,
sorttype: 'number',
formatter: 'number',
align: 'right'
}, */
{ name: 'MaxLoanAmt', label: 'MaxLoanAmt', width: 120, sorttype: 'number' , align: "right", formatter: 'currency', formatoptions: { prefix: " $", suffix: " "}},
{ name: 'AvailableCredit', label: 'Available Credit', width: 110, sorttype: 'number' , align: "right", formatter: 'currency', formatoptions: { prefix: " $", suffix: " "}},
{ name: 'Watch', label: 'Watch', width: 120, sorttype: 'number' , align: "right", template: "number",formatoptions: {decimalPlaces: 9}},
{ name: 'PledgedValue', label: 'PledgedValue',width: 120, sorttype: 'number', align: "right", formatter: 'currency', formatoptions: { prefix: " $", suffix: " "} },
{ name: 'AverageLTV', label: 'AverageLTV',width: 75, sorttype: 'number', align: "right", formatter: 'currency', formatoptions: { prefix: "", suffix: " "} }
],
additionalProperties: ["Num1"],
beforeProcessing: function (mydata) {
var item, i, n = mydata.length;
for (i = 0; i < n; i++) {
item = mydata[i];
item.LoanBalance = parseFloat($.trim(item.LoanBalance).replace(",", ""));
item.MaxLoanAmt = parseFloat($.trim(item.MaxLoanAmtMaxLoanAmt).replace(",", ""));
item.AvailableCredit = parseFloat($.trim(item.AvailableCredit).replace(",", ""));
// item.Num1 = parseInt($.trim(item.Num1).replace(",", ""), 10);
// item.Num2 = parseInt($.trim(item.Num2).replace(",", ""), 10);
}
},
iconSet: "fontAwesome",
loadonce: true,
rownumbers: true,
cmTemplate: { autoResizable: true, editable: true },
autoResizing: { compact: true },
forceClientSorting: true,
sortname: "Symbol",
height:"auto",
caption: "<b>Collateral Monitoring Red</b>",
viewrecords: true,
errorDisplayTimeout: '', //never expire
loadError: function (jqXHR, textStatus, errorThrown) {
var p = $(this).jqGrid("getGridParam"),
$errorDiv = $(this.grid.eDiv),
$errorSpan = $errorDiv.children(".ui-jqgrid-error");
$errorSpan.html("My custom error message");
$errorDiv.show();
if (p.errorDisplayTimeout) {
setTimeout(function() {
$errorSpan.empty();
$errorDiv.hide();
}, p.errorDisplayTimeout);
}
},
loadComplete: function() {
var $self = $(this),
sum = $self.jqGrid("getCol", "Price", false, "sum"),
sum1 = $self.jqGrid("getCol", "MaxLoanAmt", false, "sum");
$self.jqGrid("footerData", "set", {invdate: "Total:", Price: sum, maxLoanAmt: sum1});
}
});
加入loadError部到我的代碼和更新它。它沒有顯示自定義錯誤消息,而不是普通的404。我是否需要更新我的庫鏈接? – user244394
@ user244394:對不起,您發佈的代碼甚至不包含''在JavaScript代碼中。我發佈了兩個演示:一個使用免費的jqGrid 4.13.2,另一個使用來自GitHub的最新代碼。你可以看到它的工作原理。如果您希望我幫助您在代碼中找到錯誤,那麼您應該將URL發佈到演示中。 – Oleg
- 謝謝你,我在這裏工作的大部分在這裏是我的小提琴https://jsfiddle.net/dev2020/dc62L37z/7/有無論如何改變從紅色defauli錯誤的背景顏色?另外,如何在沒有數據返回時添加自定義消息? – user244394