Regular Expresion for data for data filter

Regular Expresion for data for data filter

ShomitShomit Posts: 5Questions: 2Answers: 0

I have used multi Select Filter.....My Table contains third column of date for which i needed seprate logic....
My Date column contains Time as as well...but i want to filter with date only for example 2016-12-02 23:59:00.0 shows only
2016-12-02 in select option tag..

1> Problem Multiple similar date are coming in drop down since there time is different.....
2>unable code the column.search() function for this functionality

please follow the else condtion.......if you want the table plss let me know

Please Please Help...
Thanks
Here is code...

$('#priorityOrders').DataTable( {
"ordering": false,
initComplete: function () {
this.api().columns().every( function () {
var column = this;
if(this[0][0]!=2)
{
var select = $('<select><option value=""></option></select>')

                .appendTo( $(column.header()))
                .on( 'change', function () {
                    var val = $.fn.dataTable.util.escapeRegex(
                        $(this).val()
                    );

                    column
                        .search( val ? '^'+val+'$' : '', true, false )
                        .draw();
                } );

            column.data().unique().sort().each( function ( d, j ) {

                select.append( '<option value="'+d+'">'+d+'</option>' )
            } );
        } 
        else
        {
             var select = $('<select><option value=""></option></select>')

                .appendTo( $(column.header()))
                .on( 'change', function () {
                    var val = $.fn.dataTable.util.escapeRegex(
                        $(this).val()
                    );
                    var dat= val.split(" ");
                    column
                        .search( '^'+val+'\s'  )
                        .draw();
                } );

            column.data().unique().sort().each( function ( d, j ) {
                var res = d.split(" ");
                //console.log(res[0]);
                select.append( '<option value="'+res[0]+'">'+res[0]+'</option>' )
            } );

        }


    }
   );
} });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin
    Answer ✓

    As you say you need to use a regular expression to match the beginning of the date time string. '^'+myValue should do it for that specific column.

    Allan

  • ShomitShomit Posts: 5Questions: 2Answers: 0

    thanks allan that worked ......can u please find solution for 1st problem as well

  • ShomitShomit Posts: 5Questions: 2Answers: 0

    thanks allan for 1st solution ......i figured out soln for second one ...tyvm

This discussion has been closed.