Jump to content

Table date formatting help


Recommended Posts



I'm trying to generate a table for particular calendar months and ran into an issue. Since we are only allowing for 5 weeks, some dates need to be combined on the 5th row (see circled dates on p2 of the template for an example). I believe there would only be 3 different occurrences, 23/30, 24/31 or 23/30 and 24/31.


I'm sure there is a way to do this but I'm stumped. I've uploaded the collected files.


Thanks in advance for any help.



Link to comment
Share on other sites

You're using some table attributes that aren't supported in FusionPro. I think it's easier to use the table API instead. With that in mind, I came up with this function, which I would put into the JavaScript Globals:

function MakeCalendar(Month, Year) // (month 1 for January, 2 for February, etc.; year four digits)
   var JSMonth = (Month-1)%12; // zero-based
   var theDate = new Date(Year, JSMonth, 1);

   var MonthName = FormatDate(theDate, "lm yyyy") ;

   // Initialize to the first Sunday of the week containing the first day of this month.
   theDate.setDate(theDate.getDate() - theDate.getDay());

   var table = new FPTable;
   for (var day = 1; day <= 7; day++)

   var row;
       if (table.Rows.length < 5)
           row = table.AddRow();

       for (var day = 0; day < 7; day++)
           if (theDate.getMonth() == JSMonth)
               var existingContent = row.Cells[day].Content;
               if (!existingContent)
                   row.Cells[day].PointSize = 60;
                   row.Cells[day].Content = theDate.getDate();
                   row.Cells[day].PointSize = 30;
                   row.Cells[day].Content = '<p br=false superratio=100 superoffset=50 subratio=100 suboffset=0>' +
                       '<superscript>' + existingContent + '</superscript>/<subscript>' + theDate.getDate() + '</subscript>';

           theDate.setDate(theDate.getDate() + 1);
   while (theDate.getMonth() != (JSMonth+1)%12)

   var title = "<p br=false quad=C><z newsize=58>" + MonthName + "<br><br>\n";
   return title + table.MakeTags();;

Then each rule can be just this (varying the month in each):

return MakeCalendar(12, 2018);

It's basically the same logic you had, just converted to use the table API, and with two extra things: one, don't add more than five rows, and two, if the cell already has a number in it, combine that with the number for the day we're adding. I used a bit of markup with superscript and subscript to get something close to the effect you're after; you can tweak this as needed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...