:: Forum >> Version 2 >>

DateFormat is not working in GRID

I have following code and date format in display of grid is not working,
Can any one guess what's happening?

function addrowsX(date){
for (var 
010i++)
        {
          var 
schedulePeriod 1;
          var 
startDate = new Date(date);
          
startDate.setMonth(startDate.getMonth() + i);
          var 
endDate = new Date(startDate);
          
endDate.setMonth(endDate.getMonth() + 1);
          
endDate.setDate(endDate.getDate() -1);
          
grdSwapSchedule.data[grdSwapSchedule.data.length] = [0,schedulePeriodstartDateendDate'N'];
          
grdSwapSchedule.addRow(grdSwapSchedule.data.length 1);
        }        
Also I have common code where i m formating cell as following:
/*
 * Converts the specified table to an Active Widgets grid.
 */
function convertTable(table)
{
  var 
dateFormat = new AW.Formats.Date();
  
dateFormat.setTextFormat("dd-MMM-yyyy");

  var 
numberFormat = new AW.Formats.Number();
  var 
stringFormat = new AW.Formats.String();

  var 
columns              = new Array();
  var 
formats              = new Array();
  var 
displayColumnIndices = new Array();

  var 
headerRow table.rows[0];

  for (var 
0headerRow.cells.lengthi++)
  {
    
columns[i] = headerRow.cells[i].innerHTML;

    if (
headerRow.cells[i].getAttribute('format') == 'date')
      
formats[i] = dateFormat;
    else if (
headerRow.cells[i].getAttribute('format') == 'number')
      
formats[i] = numberFormat;
    else
      
formats[i] = stringFormat;

    if (
headerRow.cells[i].className != 'hidden')
      
displayColumnIndices[displayColumnIndices.length] = i;
  }

  var 
rowClickListeners       = new Array();
  var 
rowDoubleClickListeners = new Array();
  var 
tooltips                = new Array();
  var 
data                    = new Array();

  
//Fixes bug where empty data causes a bug when adding new rows.
  //http://www.activewidgets.com/javascript.forum.16361.2/bug-in-addrow-if-datasource.html
  
var deleteFirstRow true;
  
data[0] = new Array();
  for (var 
0columns.lengthi++)
    
data[0][i] = '';

  for (var 
rowIndex 1rowIndex table.rows.lengthrowIndex++)
  {
    
deleteFirstRow false;

    var 
row table.rows[rowIndex];

    
data[rowIndex 1] = new Array();
    for (var 
colIndex 0colIndex row.cells.lengthcolIndex++)
      
data[rowIndex 1][colIndex] = row.cells[colIndex].innerHTML;

    if (
row.getAttribute('tooltip'))
      
tooltips[rowIndex 1] = row.getAttribute('tooltip');

    
rowClickListeners[rowIndex 1] = row.onclick;

    if (
row.getAttribute('onclick'))
      
rowDoubleClickListeners[rowIndex 1] = new Function('event''index'row.getAttribute('onclick'));

    if (
row.getAttribute('ondoubleclick'))
      
rowDoubleClickListeners[rowIndex 1] = new Function('event''index'row.getAttribute('ondoubleclick'));
  }

  var 
grid = new AW.UI.Grid();
  
grid.data data;
  
grid.setId(table.id);
  
grid.setVirtualMode(table.getAttribute('virtual') != 'false');
  
grid.setSelectionMode(table.getAttribute('selectionMode'));
  
grid.setHeaderText(columns);
  
grid.setCellFormat(formats);
  
grid.setCellText(data);
  
grid.setColumnCount(displayColumnIndices.length);
  
grid.setRowCount(data.length);

  
grid.tooltips tooltips;
  
grid.setCellTooltip(function(colrow){return this.tooltips[row? this.tooltips[row] : '';});
  if(
table.getAttribute('headerSorting') == 'false'grid.onHeaderClicked = function(){ return true;};
  
grid.rowClickListeners rowClickListeners;
  
grid.onRowClicked = function(eventindex){if (this.rowClickListeners[index]) this.rowClickListeners[index](eventindex);};
  
grid.onRowShiftClicked = function(eventindex){if (this.rowClickListeners[index]) this.rowClickListeners[index](eventindex);};

  
grid.rowDoubleClickListeners rowDoubleClickListeners;
  
grid.onRowDoubleClicked = function(eventindex){if (this.rowDoubleClickListeners[index]) this.rowDoubleClickListeners[index](eventindex);};
  
grid.onRowShiftDoubleClicked = function(eventindex){if (this.rowDoubleClickListeners[index]) this.rowDoubleClickListeners[index](eventindex);};

  var 
parentNode table.parentNode;
  
parentNode.removeChild(table);
  
parentNode.innerHTML grid;

  
//See work around for bug detailed above.
  
if (deleteFirstRow)
  {
    
grid.deleteRow(0);
    
grid.setRowState('deleted'0);
  }

  
//DO NOT MOVE THIS - setting it before the grid is displayed causes an error - NH 4/2007.
  
grid.setColumnIndices(displayColumnIndices);

  return 
grid;
}
 
and HTML code is below.

<table
                        id
="swapSchedule"
                        
class="AWTable"
                        
selectionMode="single-row"
                        
virtual="false"
                        
headerSorting="false"
                        
>
                    <
tr>
                        <
th format="number">id</th>
                        <
th format="number">Scheduled Period</th>
                        <
th format="date">Start Date</th>
                        <
th format="date">End Date</th>
                        <
th>Extra Ordinary Period</th>
                    </
tr>
                </
table>
 
Naresh C
Wednesday, May 20, 2009
Can Any one help, I am having hard time....
Naresh C
Wednesday, May 20, 2009
http://www.activewidgets.com/aw.formats.date/settextformat.html
dateFormat.setTextFormat("dd-MMM-yyyy");
NOTE: 'MMM' is not included in format pattern tokens ?
Wednesday, May 20, 2009
Even "dd-mmm-yyyy" doesn't work for me. not sure what is the problem with the grid. I make a work around although not a good thing but setting date as string in above format and unformating string and create javascript date when sending to server. what can I do !!!

If you can help me to sort out this issue i will be very thankful to you.
Also in above code convertTable(table) called on html onload function which return grdSwapSchedule grid..


Naresh C
Thursday, May 21, 2009



This topic is archived.

Back to support forum

Forum search