Tag Archive: Javascript


So, I took some time today to ponder ways of allowing TBody elements to be scrollable, and came up with a solution in jQuery, that is compatible with pretty much any browser that supports jQuery. One of the biggest desires for DOM developers using tables, is to have a scrollable tbody, to allow table headers to be visible no matter where in the table you scroll to…

The idea I had was, getting widths of columns, saving this data into an array, and then passing back this data as css widths onload and then moving the header row to a separate table.

After some messing around, I was able to come up with a solution to the issue, and am proud to offer a working example!

http://jsfiddle.net/pe295/

Although it does add an additional table to the page, at the end of the day, I’m okay with a greater interaction for the user, over a few lines of code…

I’ve been working with JSon services quite a bit these days, and one of the big issues with JSon to Javascript translation is the Date element from server side. Since JSon doesn’t return a valid Javascript date object (which in my mind, was a very poor design at the implementation of the JSon form factor), it is up to the developer to make this happen. I have written a simple Javascript function that translates from the JSon format to a user-friendly format here:

 

Code Snippet
  1. function formatDate(dateToFormat){
  2.     var d = new Date(parseInt(dateToFormat.substr(6)));
  3.     var day = d.getDay();
  4.     var m = d.getMonth() + 1;
  5.     var month = (m < 10) ? '0' + m : m;
  6.     var yy = d.getYear();
  7.     var year = (yy < 1000) ? yy + 1900 : yy;
  8.     var hour = d.getHours();
  9.     var min = d.getMinutes();
  10.  
  11.     return (day + "/" + month + "/" + year + " " + hour + ":" + min);
  12. }

 

Javascript usage is as follows:

formatDate(JsonReturnedDate);

 

This function can be modified to fulfill pretty much any date requirement you have, and can also just return a dynamic JS Date object if you would like.