Sunday, 24 May 2015

How to sort date in jQuery datatable

Hi Guys,

I got a task today to implement the date sorting in jQuery Data table. Name and plain number sorting are available in jQuery by default. But, there is nothing available in jQuery to sort the dates as the dates can be in any format. I have picked up an example where the date format is dd/mm/yyyy.

Perform the following steps to achieve custom sorting:
1) Need to tell datatable that the particular column is going to implement the custom sorting by defining sType in the aoColumns attribute.
2) Then implement both the ascending and descending methods to perform the sorting in the respective orders.

Data Table definition:

var newTable = $('#newReqTable').dataTable({
  "bProcessing" : true,
  "bAutoWidth" : true,
  "bPaginate" : true,
  "bInfo" : false,
  "sScrollY":"450px",
  "sScrollX":"100%", 
  "bScrollCollapse":true,
  "aoColumns": [
                { "sType": "ukdate" },
                null,
                null,
                null,
                null
            ]
 });

Add method for Ascending order:

When the strings a and b are formed, make sure that it should be concatenated likewise Year+Month+Date. This is because, the date format for US is MM/DD/YYYY whereas UK is DD/MM/YYYY.

jQuery.fn.dataTableExt.oSort['ukdate-asc']  = function(a,b) {
  
     var usDatea = a.split('-'); 
     var usDateb = b.split('-'); 

     var x = (usDatea[2] + usDatea[1] + usDatea[0]) * 1;
     var y = (usDateb[2] + usDateb[1] + usDateb[0]) * 1;
     console.log('ASC - first - '+a+', second - '+b+', X - '+x+',Y - '+y);
     return ((x < y) ? -1 : ((x > y) ?  1 : 0));
 };

Add method for Descending order:

jQuery.fn.dataTableExt.oSort['ukdate-desc'] = function(a,b) {
  
  var usDatea = a.split('-'); 
     var usDateb = b.split('-'); 


     var x = (usDatea[2] + usDatea[1] + usDatea[0]) * 1;
     var y = (usDateb[2] + usDateb[1] + usDateb[0]) * 1;
     console.log('DESCCCC - first - '+a+', second - '+b+', X - '+x+',Y - '+y);
     return ((x < y) ? 1 : ((x > y) ?  -1 : 0));
 };

References:

From Datatable

Example on Time sorting

Different way of Sorting

Thursday, 21 May 2015

How to display the folder structures like a tree structure in Unix

I found the following command to display the folder structure of a project or any folders in a tree-like structure.

find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

Referred from here...

Wednesday, 20 May 2015

Plugins not shown in Updated or Available sections of Jenkins CI tool

I have seen cases where the plugins are not displayed under the tabs Update and Available. It can be achieved in any of the following ways.

Prerequisite:
Make sure that you add the JDK, Ant and Maven installed/referred under the Manage Jenkins ---> Configure System.

Fix:
1) Go to: Manage Jenkins ---> Manage Plugins ---> Advanced, then click Check Now in the bottom right-hand corner.
2) See if the textbox is filled with the entry http://updates.jenkins-ci.org/update-center.json in Manage Jenkins ---> Manage Plugins ---> Advanced ---> Update Site

Tuesday, 19 May 2015

Increase the Memory in Tomcat

Just add the following contents to the file located in \bin\catalina.bat (for Windows) or \bin\catalina.sh (for unix). Increase the -Xmx... and permGen setting based on your memory capacity and application needs.
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"

Other way of doing is:
Create a file named setenv.bat and place it in %CATALINA_HOME%\bin\
And then add the following content to the file

set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m

Tomcat will execute the file setenv.bat if its there.

How to remove files recursively in Git

A tool used to generate .bak files when it is used for comparing two files. One way to fix this is to mentioned the extension .bak in .gitignore file. The other way is to manually find and the remove the files recrusively

find . | grep .bak | xargs rm -rf

Sunday, 17 May 2015

How to debug Angular JS using Batarang

Batarang is a tool used to debug Angular JS application. There is a plugin available for Chrome, which can be downloaded from Batarang

The detailed explanation on how to use the tool is available in Youtube - AngularJS-Batarang Debugger

Thursday, 14 May 2015

How to left pad zeros for a column in Sql Server

I had a requirement where I need to left pad zeros for a column in MS SQL Server. I thought the below methods would be helpful for the concerned.


select empid,          
       replicate('0', 6 - len(salary)) + cast (salary as varchar) as salary
from   emp;  

empid       salary
----------- -----------
1           000300
2           000030
3           500000
4           001000

(4 row(s) affected)