2
我想在網格上顯示日期爲N/A,因爲它在數據庫中爲NULL,否則爲正常日期格式。 目前我有這樣的代碼:在JQGrid中爲日期字段設置自定義格式化程序
name: 'Handshake_Actual_Date', index: 'Handshake_Actual_Date', search: false,
editable:true, align: "left", width: 75, formatter: "date", formatoptions:
{newformat:"m/d/Y" },
editoptions: {
size: 20,
dataInit: function (el) {
$(el).datepicker({ dateFormat: 'mm/d/yy' });
},
defaultValue: function() {
var currentTime = new Date();
var month = parseInt(currentTime.getMonth() + 1);
month = month <= 9 ? "0" + month : month;
var day = currentTime.getDate();
day = day <= 9 ? "0" + day : day;
var year = currentTime.getFullYear();
return day + "/" + month + "/" + year;
}
}
它工作得很好,但我想自定義格式如下圖所示:
function myFormatter (cellvalue, options, rowObject) {
if(cellvalue==null)
{
return "N/A";
}
else
{
return $.fn.fmatter.date(cellvalue, options, rowObject);
}
}
,但它不工作..! 你可以在這裏看到的代碼示例:http://jsfiddle.net/35Larwva/
thnks!我嘗試將其改爲您所說的內容,但我的網格無法加載,它只是在一個框中顯示加載。事實上,即使只寫 返回fn.fmatter.call(this,「date」,cellvalue,options,rowObject);在沒有其他的情況下,在自定義格式化程序中,不起作用 \t } – user3814961 2014-09-05 13:20:54
@ user3814961:可能有很多其他原因。加載框主要意味着您使用的JavaScript代碼存在錯誤。例如'NULL'表示未定義的全局變量,名稱爲NULL,'null'表示您知道的空。您應該在調試器中啓動代碼,以準確查看哪個錯誤以及您擁有哪行代碼(例如,按F12啓動Developer Tools,然後啓動JavaScript調試器)。例如,你可以在jqFiddle中發佈你的代碼(例如獲取[demo](例如http://jsfiddle.net/OlegKi/35k71pmw/2/並修改它以包含你的代碼))併發布鏈接 – Oleg 2014-09-05 13:29:10
@Oleg你能請看看這個問題。謝謝[鏈接] http://stackoverflow.com/questions/25694281/jqgrid-how-to-add-a-edittype-checkmark-that-posts-date-to-column – NewHistoricForm 2014-09-05 21:37:47