Free jqGrid restoring date with custom formatter after cancelling inline edit - date

After inline edit is cancelled, the date column comes back as undefined instead of restoring the original value. Column is defined as following (dates are coming in 1970-01-01 format):
{name:'Release<br>Date',index:'Street_Date', sorttype:"date", width:70,
formatter: function (cellvalue, options, rowObject) {
return cellvalue === ('1970-01-01') ? "" : $.fn.fmatter.call(this, "date", cellvalue, options, rowObject);
},
formatoptions: {newformat:'d M y'},
editable:true,
editoptions: {
size:9,
dataInit: function(el, options) {
$(el).datepicker({
dateFormat: "d M y",
defaultDate: '01 Jan 70',
onSelect: function(dateText, inst) {
}
});
}
},
searchoptions: {
sopt: ['eq','ne','ge','le'],
dataInit: function (elem) {
$(elem).datepicker({ showButtonPanel: true, dateFormat: 'yy-mm-dd' })
}
}
},
The inline edit is setup as following:
ondblClickRow: function (rowid) {
var savedRows = $grid.jqGrid("getGridParam", "savedRow");
if (savedRows.length > 0 && savedRows[0].id !== rowid) {
// cancel editing
$grid.jqGrid("restoreRow", savedRows[0].id);
}
if (savedRows.length === 0) {
$grid.jqGrid("editRow", rowid, editOptions);
}
}
When Grid is loaded, the date shown like 07 Aug 18, entering the inline editing by double click, the date is still 07 Aug 18. After cancelling the edit either by clicking away or clicking Cancel button, date becomes NaN undefined N. After refresh, it comes back correctly though.
How to preserve the correct date after cancelling editing?
Grid behaves correctly with formatter: date
free jqGrid v jqGrid 4.13.5

Maybe the author of free-jqGrid will help better, but I would recommend you to add additional parameter (action='edit') when the formatter is called. Code below:
formatter: function (cellvalue, options, rowObject) {
return cellvalue === ('1970-01-01') ? "" : $.fn.fmatter.call(this, "date", cellvalue, options, rowObject, "edit");
},
Note the last parameter in $.fn.fmatter.call
UPDATE
This is working in my tests.
Since you use a custom date fomatter it is needed the value in savedRows to be unformated in order to be saved correct. In case of default formatter = date this is done automatically.
Below is the code that can be used, suppose you know the index of the field in colModel:
ondblClickRow: function (rowid) {
var savedRows = $grid.jqGrid("getGridParam", "savedRow");
if (savedRows.length > 0 && savedRows[0].id !== rowid) {
// cancel editing
savedRows[0].Release_Date = $.unformat.date.call($grid[0], savedRows[0].Release_Date, $grid[0].p.colModel[1]);
$grid.jqGrid("restoreRow", savedRows[0].id);
}
if (savedRows.length === 0) {
$grid.jqGrid("editRow", rowid, editOptions);
}
}

Related

Matching a date on a calendar to another field

Ok, I have a calendar on my page and each day is a formatted version of that date, eg.
Jan 2021
1 2 3 4
5 6 7 8
etc..
so the 1 cell will contain 1/1/2021 (but formatted to just show '1' [d])
I also have a cell (K5) on that page for a user to enter a date eg:[1/1/2021]
What i'd like is a script that changes the border colour of the day in the calendar if it matches the user entry cell.
The code:
function onEdit(e) {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
var date = sheet.getRange("K5").getValue();
if (e.range.getValue()== date) {
e.range.setBorder(true, true, true, true, true, true, "red", SpreadsheetApp.BorderStyle.solid); }
};
This doesn't work and I can't think of a way of having the code work for every cell of the calendar (there are 2 years worth so over 1000 cells).
It doesn't need to be onEdit, i was just testing to see if the actual setBorder function worked (which it does)
Also, I cant use conditional formatting as I've already used that to change to bg and font colours for something else (and there's no option to change boarder colour anyway)
I've made a mini version with just Jan if you'd like to have a look and see what you can do:
https://docs.google.com/spreadsheets/d/1oV4lE8cQB-e2bVc_HgiGM31ivk3uHxPcqsSdLdCxsmQ/edit?usp=sharing
One alternative to looking for all the dates would be to use a formula to show the dates and their addresses in a different sheet. This formula will output a series of dates and their addresses for your holidays. It can then be read with an onEdit() script to put borders on the correct addresses:
Formula:
=ARRAYFORMULA(IFERROR(QUERY(SPLIT(FLATTEN(N(Calendar!E9:AY)&"|"&ROW(Calendar!E9:AY)&"|"&COLUMN(Calendar!E9:AY)&"|"&LEN(TO_TEXT(Calendar!E9:AY))),"|",0,0),"select Col1,Col2,Col3 where Col4<3 and ("&TEXTJOIN(" or",TRUE," Col1="&FILTER(Calendar!BE28:BE100,Calendar!BE28:BE100<>""))&")")))
Script:
function onEdit(e){
holidayBorders(e);
}
function holidayBorders(e){
var sheet = e.range.getSheet();
if(e.value && sheet.getName()=='Calendar' && e.range.getColumn()==57 && e.range.getRow() >= 28){
SpreadsheetApp.flush();
Utilities.sleep(10000);
var datasheet = e.source.getSheetByName('DATA');
var rcs = datasheet.getRange('AQ3:AR').getValues().filter(e=> e[0]);
for (let i=0;i<rcs.length;i++){
sheet.getRange(rcs[i][0],rcs[i][1]).setBorder(true, true, true, true, true, true, "red", SpreadsheetApp.BorderStyle.solid);
}
}
}
You could do the following:
Get all values in your range, using getValues().
Iterate through all values in the resulting 2D array.
For each value, check if (1) the value is a Date (for example, using instanceof) and whether the two dates are from the same day (for example, doing this).
If both conditions are met, set the border.
Code snippet:
function setBorders() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
var date = sheet.getRange("K5").getValue();
var firstRow = 7;
var firstCol = 5;
var data = sheet.getRange(firstRow, firstCol, sheet.getLastRow() - firstRow + 1, sheet.getLastColumn() - firstCol + 1).getValues();
data.forEach((row, i) => {
row.forEach((value, j) => {
if (value instanceof Date && sameDay(date, value)) {
sheet.getRange(i + firstRow, j + firstCol).setBorder(true, true, true, true, true, true, "red", SpreadsheetApp.BorderStyle.solid);
}
});
})
}
function sameDay(date1, date2) {
return date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate();
}

Rally Or Filter on Release Start Date sdk

I need help with the following code. The uncommented code works fine, but I need to get the commented code to work. See //value: releaseStartDateISO in my code below. Specifically, filter-2 doesn't work. I want to display defects that are active (ie, filter 1- not closed) or defects with a Closed Date greater than Release Start Date (filter 2). This will give me all active defects plus any that were closed during the current sprint. I tried converting Release Start Date to ISO, but this doesn't work. It seems like rally is not recognizing ReleaseStartDate and I don't know why. Note: This is the code from rally git. I added the "or filter" https://github.com/RallyApps/app-catalog/tree/master/src/apps/defectsummarymatrix
Thanks for your help!
_showComponentIfNeeded: function(component) {
if (component && component.isHidden()) {
component.show();
}
},
_initializeAllDefectStore: function(release) {
//var releaseStartDate = release.get('ReleaseStartDate');
//var releaseStartDateISO = Rally.util.DateTime.toIsoString(releaseStartDate,true);
var filter = Ext.create('Rally.data.QueryFilter', {
property: 'State',
operator: '!=',
value: 'Closed'
});
filter = filter.or({
property: 'ClosedDate',
operator: '>',
//value: releaseStartDateISO
value: '2014-09-10'
});
filter.toString();
if (this.releaseFilter && this.defectModel) {
this.allDefectStore = Ext.create('Rally.data.wsapi.Store', {
model: this.defectModel,
fetch: ['State','Priority'],
autoLoad: true,
limit: Infinity,
context: this.getContext().getDataContext(),
filters : [this.releaseFilter,filter],
listeners: {
load: this._onAllDefectStoreLoaded,
scope: this
}
});
}
},
_onAllDefectStoreLoaded: function(store, records, successful, eOpts) {
this._initializeMatrixTable();
this._populateMatrixTable(records);
this._createPriorityRecords(records);
this._updateMatrixGrid();
this.setLoading(false);
},
What is the value of release.get('ReleaseStartDate')? Is it possible the release record you have does not have that field populated?

DOJO Grid Date Text box shows 1970 when user deletes the date

I am new in DOJO grid. I have a grid which have multiple Date Boxes under project Start date for each user. When admin selects one date (e.g. user1 Start Date) and moves on to other field (e.g. description) and comes back and deletes the date (user1 Start Date) it shows 1 Jan 1970. I used formatter and changed the display, but when I submit date then its showing 1 Jan 1970 as selected date. How can I set it for Blank Value? If user deletes the date I want to show Blank value there. How am I suppose to achieve this?
Code I use is as follows
smallLayout.push({
field : editableFieldNames[index],
name : editableColumnNames[index],
sortable : true,
filterable : true,
autoComplete: true,
editable : true,
width : '100px',
styles : 'text-align: left; background:#A3C8EC; color: #000;',
type : dojox.grid.cells.DateTextBox,
constraint: {
datePattern : "dd MMM yyyy",
selector : "date"
},
formatter: formatDate
});
// Formatter to return date in correct format
var formatDate = function (val, rowIdx, cell) {
//dijit.byId('myid').reset();
cell.customClasses.push('noBackgroundClass');
if (val != '0000-00-00' && val != null) {
// If date is comming from database
if (typeof val == 'string') {
return "<div class = 'editableCell'>" + val + "</div>";
} else {
console.log(cell);
if (val.getFullYear == '1970') {
return "<div class = 'editableCell'><div>";
}
return "<div class = 'editableCell'>"
+ val.getDate() + ' '
+ month[val.getMonth() + 1] + ' '
+ val.getFullYear() + "</div>"
;
}
} else {
return "<div class = 'editableCell'><div>";
}
}
Thank You,
Amit

how to validate datefield before select in extjs 3.4

i am using extjs 3.4 add add datefield in portal for selection of date range.Start date and end date means if i select 28 jan 2014 in start date then i want to validate end date after 28 jan 2014 is display with in 30 days interval only .
and i also want to validate difference between start date and end in only 30 days
{
id:'funnelStartId',
xtype: 'datefield',
format : 'd-M-Y',
editable:false,
emptyText:'Start date',
listeners:{
select: function (value,date){
getFunnelDateRange()
}
}
},{
id:'funnelEndId',
`enter code here` xtype: 'datefield',
format : 'd-M-Y',
editable:false,
emptyText:'End date',
listeners:{
select: function (value,date){
getFunnelDateRange()
}
}
}
I think you may be able to get a similar behavior to the one you describe by setting the min and max values of the datefield on select:
var dateValidate = function() {
var dateFld1 = Ext.getCmp('funnelStartId');
var dateFld2 = Ext.getCmp('funnelEndId');
startValue = dateFld1.getValue();
endValue = dateFld2.getValue();
maxEndValue = startValue.add(Date.DAY, 30);
if (endValue < startValue || endValue > maxEndValue) {
dateFld2.setValue(null);
}
dateFld2.setMinValue(startValue);
dateFld2.setMaxValue(maxEndValue);
}
I have a created fiddle demonstrating.

jqGrid filterToolbar - filter on DateTime using jquery ui datepicker

I have been looking at filtering jqGrid by datetime using the filterToolbar.
My question is based on Olegs excellent answer here.
I finally figured out how to trigger toolbar search on date as follows:
colModel: [{
name: 'RequestDate',
index: 'RequestDate',
formatter: 'date',
formatoptions: {
newformat: 'm/d/Y h:iA'
},
searchoptions: {
sopt: ['eq'],
dataInit: function (elem) {
$(elem).datepicker({
changeYear: true,
changeMonth: true,
onSelect: function (dateText, inst) {
setTimeout(function () {
$('#MyGrid')[0].triggerToolbar();
}, 50);
}
});
}
}
}]
Now when selecting the date from the picker I want to return all records for the given date ignoring the time.
I have tried updating the FilterObjectSet method with no luck. Has anyone been able to implement this successfully?
What I've tried: (see the code in Olegs linked solution)
Setting the FormatMapping to "(dateadd(dd,0, datediff(dd,0, it.{0})) = #p{1})" and
addingSystem.DateTime to the switch statement:
case "System.DateTime":
param = new ObjectParameter("p" + iParam, Convert.ToDateTime(rule.data));
break;
But this will result in a EntitySqlException:
'dateadd' cannot be resolved into a valid type or function.
Does anyone have a solution?
Ok figured it out this morning:
Added a new Operation:
de //de - date equals
Added a new string to FormatMapping that uses SqlServer.datediff:
"(SqlServer.datediff('DAY', it.{0} , #p{1}) = 0)" //de - date equals
and added the date case:
case "System.DateTime":
param = new ObjectParameter("p" + iParam, Convert.ToDateTime(rule.data));
break;
Changed sopt in colModel to sopt: ['de']