Date range filter

Date range filter

lifesoundlifesound Posts: 2Questions: 2Answers: 0

Sorry for the recurrent question

I have read evey thing to do that and it does,not work

Can you help

Answers

  • dlm1897@gmail.comdlm1897@gmail.com Posts: 1Questions: 0Answers: 0

    I'm also looking for help. So far, I've been unsuccessful in searching a single date column by a date range. Any help would be appreciated.

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    I got some stuff in the works that might help you. It should be done tomorrow

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Below is an if a function for date range. Note that id depends on the popular plugin called moments (http://momentjs.com/ ).

    You can see this run at http://live.datatables.net/zuciyawi/1/edit

    take note of inline comments

        $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {
        
    // If min or max are empty or invalid they are ignored
    // if min or max are valid and the date in the column is blank or invalid, its filtered out.
              
            var valid = true;
            var min = moment($("#txtMin").val());
            if (!min.isValid()) { min = null; }
    
            var max = moment($("#txtMax").val());
            if (!max.isValid()) { max = null; }
    
            if (min === null && max === null) {
                // no filter applied or no date columns
                valid = true;
            }
            else {
               // I coded this to look for columns of type date
              // you can easily change this to look in specific columns.
                $.each(settings.aoColumns, function (i, col) {
                  
                    if (col.type == "date") {
                        var cDate = moment(data[i]);
                    
                        if (cDate.isValid()) {
                            if (max !== null && max.isBefore(cDate)) {
                                valid = false;
                            }
                            if (min !== null && cDate.isBefore(min)) {
                                valid = false;
                            }
                        }
                        else {
                            valid = false;
                        }
                    }
                });
            }
            return valid;
    });
    
    $(document).ready( function () {
        $("#btnGo").click(function () {
            $('#example').DataTable().draw();
        });
        var table = $('#example').DataTable(
    
          {columns:[{name:"Name"},
                    {name:"Postition"},
                    {name:"Office"},
                    {name:"Age"},
                   // this is where I set the column that should be filtered by setting type date.
                    {name:"Start Date", type:"date"},
                    {name:"Salary"}]}
        );
    } );
    
    
  • ravidarjiravidarji Posts: 1Questions: 0Answers: 0

    is are not working for me, please give me solution how can i set button for daterage filter

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736
    edited September 2019

    @ravidarji the above example from Bindrid seems to work. Does it work for you?

    If you need help please update the example to show the issue you are having.

    Kevin

This discussion has been closed.