2

I want to diplay date on grid as N/A incase it is NULL in the database, or else in normal date format. At present I have this code:

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;
}
}

It works perfectly well but I want a custom formatter like below :

function myFormatter (cellvalue, options, rowObject) {
if(cellvalue==null)
{
return "N/A";
}
else
{
return $.fn.fmatter.date(cellvalue, options, rowObject);
}
}

but it is not working..! for an example you can see the code here : http://jsfiddle.net/35Larwva/

1 Answers1

3

Try to replace

$.fn.fmatter.date(cellvalue, options, rowObject)

to

$.fn.fmatter.call(this, "date", cellvalue, options, rowObject);

Moreover I recommend you to use more correct JavaScript code: cellvalue==NULL should be replaced to cellvalue === null, you should use ; at the end of statements (after return "N/A" for example) and it's better always use {} for if and else statements.

UPDATED: I fixed your jqfiddle demo so that it work now: http://jsfiddle.net/OlegKi/35Larwva/2/

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thnks.! I tried changing it to what you said, but my grid doesn't load, it just show Loading in a box. Infact even writing just return fn.fmatter.call(this, "date", cellvalue, options, rowObject); in the custom formatter without if else , doesn't work } – user3814961 Sep 05 '14 at 13:20
  • @user3814961: It could be a lot of other reasons. Loading box means mostly that there is an error in JavaScript code which you use. For example `NULL` means undefined global variable with the name `NULL` and `null` means the null which you knows. You should start the code in debugger to see which error exactly and in which line of code you have (press F12 for example to start Developer Tools and then start JavaScript debugger). You can post your code in jqFiddle for example (get [the demo](http://jsfiddle.net/OlegKi/35k71pmw/2/ for example and modify it to include your code)) and post the link – Oleg Sep 05 '14 at 13:29
  • @Oleg Could you please take a look at this problem.Thanks [link]http://stackoverflow.com/questions/25694281/jqgrid-how-to-add-a-edittype-checkmark-that-posts-date-to-column – NewHistoricForm Sep 05 '14 at 21:37
  • @NewHistoricForm: Sorry, but I don't full understand your question. You wrote that you want to place "date to both" or todays day near the checkbox. Which column of the grid (or the property of input data) contains the "date to both"? You wrote about new "editype": "checkmark". You can add new colum of the type `edittype:'checkbox'` and implement appending the checkbox in edit form with some date information. You can use "change" or "click" event on the checkbox to handle the checking/unchecking of it and modifying the date. I still not full understand your question. – Oleg Sep 05 '14 at 23:14
  • @Oleg Yes. That could work. If I add column of `edittype:'checkbox'` only a checkbox is shown in editform. I need current date to appear next to checkbox when checked and that date added to the cell after submit or un-checked then a "NULL" is sent back to leave cell empty.Could you please put example on page please? – NewHistoricForm Sep 05 '14 at 23:21
  • @NewHistoricForm: It's too late now in Germany. :-( I'll try to answer you at the weekend. – Oleg Sep 06 '14 at 00:32
  • @Oleg : The error showed is fn undefined.. What do I do about this..?Pls help – user3814961 Sep 08 '14 at 09:00
  • @user3814961: Look at [the modified demo](http://jsfiddle.net/OlegKi/35Larwva/2/) which works. By the way your demo used `fn.fmatter.date` instead of `$.fn.fmatter.date`. – Oleg Sep 08 '14 at 11:00
  • ohh great!! Thanks a lot @Oleg ..lemme see by incorporating it into my project :D – user3814961 Sep 08 '14 at 13:50
  • @Oleg Could please help. I really need your expertise to point me in the right direction. Thank you.[link]http://stackoverflow.com/questions/25694281/jqgrid-how-to-add-a-edittype-checkmark-that-posts-date-to-column – NewHistoricForm Sep 08 '14 at 15:20
  • @Oleg How to make the `datefortmat` come out as 9/9/2014. Right now it only shows up as 09/09/2014. – NewHistoricForm Sep 11 '14 at 21:29
  • @NewHistoricForm: I would recommend you to use ISO 8601 date format ("2014-09-09") for any dates which will transferred between client and the server. The formatoptions `newformat: "n/j/Y"` is default for `grid.locale-en.js`, so it's unclear why you have `09/09/2014`. Probably you do use wrong value for `formatoptions.newformat`? – Oleg Sep 12 '14 at 05:06
  • @Oleg Thanks for the help. Could you pease help with this problem. Your insight would be extremely helpful. [tinyMCE in custom textarea column](http://stackoverflow.com/questions/25861647/how-do-i-make-tinymce-editor-stay-in-my-jqgrid-textarea-formedit-form-after-firs) – NewHistoricForm Sep 16 '14 at 11:38