0

enter image description hereenter image description hereI created a filtered table which is working fine except it doesn't filter on date column.I need it to filter on date column as well. If the column datatype is string then the code I mentioned works very well, If the column datatype is number then I have to use toString() to convert it into string then filter works for that column as well but If I am trying to use toString() for any date/time column it doesn't work and not able to filter. I tried many function to convert it into string since filter works on string data type but no success. Below is the step I perform:

  • I try to search any data from the search box if it matches with any character then it will filter out those records only.
  • If it doesnt match then return a blank list.
  • If I remove my search string then whole table will be returned.

enter image description here`

var searchString = searchtext.toUpperCase();
        for (var ent in entLst) {
            if ((!$A.util.isUndefinedOrNull(entLst[ent].RECEIVED_DATE__c.toString() && entLst[ent].RECEIVED_DATE__c.toString().indexOf(searchString) != -1)) {
                filteredLst.push(entLst[ent]);
            }
        }
0

2 Answers 2

2

The actual issue here seems to be that RECEIVED_DATE__c returns a dateTime field value, such as 2019-07-16T11:48:00.000Z, therefore, searching for Jul 16, or something similar will never return results. Searching on dates is a very uncommon use case, normally, you would want to apply filters on specific months or date range filters to facilitate rendering results based on a certain date range or month.

In a nutshell, your component is working as designed, you just were not searching in the appropriate format, and your current component does not support what you were attempting to do.

If you are keen on converting the date format, there are numerous resources online:

4
  • Is it possible to format 2019-07-16T11:48:00.000Z into Jul 16, 2019, 06:48:00 AM so that my search will work Jul 21, 2019 at 19:52
  • updated my answer, there are numerous online resources explaining how to do so.
    – glls
    Jul 21, 2019 at 19:55
  • Thanks @glls your debugging way helped me to get this. Jul 21, 2019 at 20:43
  • it was you who debugged, i simply pointed you in the right direction =)
    – glls
    Jul 21, 2019 at 21:09
1
  <aura:attribute name="format" type="string" default="MMM-DD-YYYY"/>
  <aura:attribute name="formatedDate" type="Date"/>

  var searchString = searchtext.toUpperCase();
        for (var ent in entLst) {
            var dateValue  = new Date(entLst[ent].RECEIVED_DATE__c);
            component.set('v.formatedDate',$A.localizationService.formatDate(dateValue,component.get('v.format')));
            var RECEIVED_DATE__c = component.get('v.formatedDate');
            if ((!$A.util.isUndefinedOrNull(RECEIVED_DATE__c) && RECEIVED_DATE__c.toUpperCase().indexOf(searchString) != -1)) {
                filteredLst.push(entLst[ent]);
            }
        }

Finally I am able to achieve this.

  • First I formated my date to MMM-DD-YY only.
  • Next I used the above code.

Working :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .