Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Richard White on Jan 07, 2008 05:43
open dhtmlx forum
calendar field when filter used in UK

Hi,

we have a calendar field in a grid for date of birth. on that same field we have one of your filters (which puts a search box at the top of the column).

we are based in the UK and have used the following line of code to set the date format to show as dd/mm/yyyy

// set date format to (dd/mm/yyyy)
grid.setDateFormat("d/m/y");

this shows the date as we require it perfectly i.e. 23/01/2008

however when we do a search for a date in the columns search / filter box it works on the format of mm/dd/yyyy so to find this date we have to type 01/23/2008

how can we change it so that we can do a search for 23/01/2008 and it will find it, so to search on the format of dd/mm/yyyy

thanks very much

richard
Answer posted by Support on Jan 08, 2008 02:43
Yes, the described situation is expected limitation of filters, while grid show formated output, filter use inner value - in you case it date in javascript format ( which is mm/dd/yyyy )
The problem can be resolved with next customization, just add next code to you page

dhtmlXGridObject.prototype._in_header_date_filter=function(t,i){
    t.innerHTML="<input type='text' style='width:98%; font-size:8pt; font-family:Tahoma; -moz-user-select:text; '>";
    t.onclick=t.onmousedown = function(e){ (e||event).cancelBubble=true; return true; }
    t.onselectstart=function(){ return (event.cancelBubble=true); }
    this.makeFilter(t.firstChild,i);
    t.firstChild._filter=function(){ //this code format date
       temp=this.value.split("/");
       if (temp.length!=3) return "";  //not complete date
       return temp[1]+"/"+temp[0]+"/"+temp[2]
    }
    this._filters_ready();
}

This code add one more auto-filter
    #date_filter
which will accept date in dd/mm/yyyy format
Answer posted by richard white on Jan 08, 2008 05:52
hi, great thanks very much i will try this

thanks again
Answer posted by Richard White on Jan 14, 2008 07:08
hi

the only problem i see with this is as follows: in the code:

dhtmlXGridObject.prototype._in_header_date_filter=function(t,i){
    t.innerHTML="<input type='text' style='width:98%; font-size:8pt; font-family:Tahoma; -moz-user-select:text; '>";
    t.onclick=t.onmousedown = function(e){ (e||event).cancelBubble=true; return true; }
    t.onselectstart=function(){ return (event.cancelBubble=true); }
    this.makeFilter(t.firstChild,i);
    t.firstChild._filter=function(){ //this code format date
       temp=this.value.split("/");
       if (temp.length!=3) return "";  //not complete date
       return temp[1]+"/"+temp[0]+"/"+temp[2]
    }
    this._filters_ready();
   
   
    }

there is a line that says if temp.length!=3 then return ""

the problem is that it will only do a filter if i have put in at least dd/mm/ then it will do the filter - otherwise if i just type a year or a month then it wont do any filtering at all. whereas if i dont add this bit of code then it does start filtering no matter what i do

look forward to your reply, thanks
Answer posted by Support on Jan 14, 2008 08:15
This line was added purposely to prevent sorting by incomplete date, you can modify it in any necessary way, for example

if (temp.length==2) return temp[1]+"/"+temp[0]
if (temp.length!=3) return "";  //not complete date
       return temp[1]+"/"+temp[0]+"/"+temp[2]

which will allow filtering if you entered at least day and month

Answer posted by richard white on Jan 14, 2008 08:40
thanks for this, except on the normal date filter i can put in 03 and it filters the rows whether 03 is in the day, month, or year. this is the similar example i want. i want them to be able to type in anything and it finds it anywhere in the date column and filters out the rest. this is the normal behaviour, i want it to do this but on dd/mm/yyyy instead

as in the code you gave me, if they were type in just the year, it wouldnt filter anything but on the normal filter it would.

thanks
Answer posted by richard white on Jan 14, 2008 08:43
its ok i managed to do it by adding the code you gave me plus adding
if(temp.length==1) return this.value;