How to programatically divide date into Months and years

How to programatically divide date into Months and years

amey1309amey1309 Posts: 28Questions: 0Answers: 0
edited November 2013 in Plug-ins
Hello,
I am using "fnGetColumnData" api(http://www.datatables.net/release-datatables/examples/api/multi_filter_select.html) to sort the individual column.Its working fine but I want it to split the date(FORMAT:2012-10-19) column into user readable Months(JAN,FEB etc) and years and create 2 different select boxes for "DATE'" column and sort accordingly.How do I do it?

Replies

  • amey1309amey1309 Posts: 28Questions: 0Answers: 0
    edited November 2013
    I have found the solution though may not be the efficient one.Comments are always welcome.



    [code]
    function fnCreateSelect( aData )
    {

    var r='', i, iLen=aData.length;
    for ( i=0 ; i

    } );
    [/code]

    [quote] Add a select menu for each TH element in the table footer [/quote]

    [code]
    $("tfoot th").each( function ( i ) {


    if(i==0)
    {
    //var d = new Date(val);

    this.innerHTML = fnCreateyearSelect( oTable.fnGetColumnData(i) )+fnCreatemonthSelect( oTable.fnGetColumnData(i) );
    // this.innerHTML = fnCreatemonthSelect( oTable.fnGetColumnData(i) );
    // this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) );
    }
    else
    this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) );
    [/code]



    [quote]Select the value from select options to be sorted [/quote]

    [code]
    $('select', this).change( function () {
    if(i==0)
    {//[/d]{4}\-09\-[/d]{2} 2013\-09\-12 2013\-09\-[/d]{2} 2013\-09\-[0-9]{2}
    var regex;
    var val =$(this).val();

    if($(this).attr('id')=="years")
    {
    var month=$("#months").val();
    var year =$(this).val();

    }
    else if($(this).attr('id')=="months")
    {
    var month =$(this).val();
    var year=$("#years").val();
    }


    if(month!="" && year=="")
    {
    //regex= "^[0-9]{4}\-"+month+"\-[0-9]{2}$";
    regex= "^[0-9]{4}\-("+month+"|0"+month+")\-[0-9]{2}$";
    oTable.fnFilter( regex, i ,true);
    }
    else if(month=="" && year!="")
    {
    regex= "^"+year+"\-[0-9]{2}\-[0-9]{2}$";
    oTable.fnFilter(regex, i ,true);
    }
    else if(month=="" && year=="")
    {
    oTable.fnFilter( month, i );
    }
    else if(month!="" && year!="")
    {
    regex= "^"+year+"\-("+month+"|0"+month+")\-[0-9]{2}$";
    oTable.fnFilter(regex, i ,true);
    }
    }
    else
    oTable.fnFilter( $(this).val(), i );
    } );
    } );
    } );

    [/code]
This discussion has been closed.