Filter the data which hasn't exceeded a particular time limit in Repeater!

Hi Team

I was searching how to build a filter for a repeater connected to dataset showing only those items that have not exceeded -

Start Date (It is a field name in my dataset of type DATE & TIME) + 100

Also Start Date is different for each item (most probably) and this condition should check for each entry and show in repeater.

I would be highly obliged if you could help me.

What does it mean “+100”? 100 milliseconds? 100 hours? 100 days?

Days

Actually Repeater is like expiry date, where users get removed from the repeater when its expiry has ended.


Start Date is filled by me in the data.


$w.onReady(() => {
$w('#dataset1').onReady(() => {
$w('#dataset1').getItems(0, 1000)
.then(r => {
const data = r.items.filter(e => new Date().getTime()  > e.startTime.getTime()  +  100 *  86400000);
 $w('#repeater1').data = data;
})
})
})

Thanks For Your Help.
This code will help me a lot.

But,

@jonatandor35 I have a confusion where I have to initialize by Start Date Field (Field in my dataset) value and use that in this code .:slightly_smiling_face:

@rinshulgoel I’m not sure what you’re asking.
Have a look at this part: e . startTime . getTime ()
instead of startTime, use your field key.

Hi guys,

Please help, getting an error while using the mentioned code.

An error occurred in one of datasetReady callbacks TypeError: Cannot read property 'getTime' of undefined

Please help its urgent!!

You probably have at least 1 item without a startTime value and therefore it gives you an error.
You can do the following:

$w.onReady(() => {
$w('#dataset1').onReady(() => {
$w('#dataset1').getItems(0, 1000)
.then(r => {
let data = r.items.filter(e => e.startTime instanceof Date);
 data = data.filter(e => new Date().getTime()  > e.startTime.getTime()  +  100 *  86400000);
 $w('#repeater1').data = data;
})
})
})

Hi, @jonatandor35

Thanks for it, it was one of the problem

But,

Sorry to say, it is not working there is no change in the repeater items (Repeater is only working on data setting filter ).
I think you understand my question incorrectly.

See suppose (in Excel)-

I have 7 customers with different invoice date-


After using the filter on Invoice Date Column That to show only those that have not exceeded its Invoice Date + 100 Days till today

The data shows only this much item -



So, I mean I want my repeater to show only this one customer.
Also I have about 6000 customer in dataset.

I hope you understand.

Thanks in advance!!

@rinshulgoel Please post your code.

@jonatandor35

$w.onReady(() => {
  $w('#dataset1').onReady(() => 
  $w('#dataset1').getItems(0, 5000)
  .then(r => {
 let data = r.items.filter(e => e.dlrInvoiceDate instanceof Date);
    data = data.filter(e => new Date().getTime()  < e.dlrInvoiceDate.getTime()  +  547 *  86400000);
    $w('#repeater1').data = data;
    })
  )
})

@rinshulgoel you’re missing some parenthesis (see in purple):

$w.onReady(() => {
  $w('#dataset1').onReady(() => {
  $w('#dataset1').getItems(0, 5000)
  .then(r => {
 let data = r.items.filter(e => e.dlrInvoiceDate instanceof Date);
    data = data.filter(e => new Date().getTime()  < e.dlrInvoiceDate.getTime()  +  547 *  86400000);
    $w('#repeater1').data = data;
    })
  })
})

@rinshulgoel
Still not solved here?

@rinshulgoel
What is your current state? Your current code?
Where did you stuck ?

J.D. gave you this as last answer…

$w.onReady(() => {
  $w('#dataset1').onReady(() => 
  $w('#dataset1').getItems(0, 5000)
  .then(r => {
 let data = r.items.filter(e => e.dlrInvoiceDate instanceof Date);
    data = data.filter(e => new Date().getTime()  < e.dlrInvoiceDate.getTime()  +  547 *  86400000);
    $w('#repeater1').data = data;
    })
  )
})

@russian-dima Using the above code nothing happens to the repeater.

This was the last code

$w.onReady(() => {
  $w('#dataset1').onReady(() => {
  $w('#dataset1').getItems(0, 5000)
  .then(r => {
 let data = r.items.filter(e => e.dlrInvoiceDate instanceof Date);
    data = data.filter(e => new Date().getTime()  < e.dlrInvoiceDate.getTime()  +  547 *  86400000);
    $w('#repeater1').data = data;
    })
  })
})

Can there be some other way where I could use Between method of Wix data filter-

Steps-

  1. Fetch the value from the cell in a variable from a dataset. (1st Date)

  2. Then in another variable set the value to be equal to first variable + 547 days. (2nd Date)

  3. And then filter the data.

For Example-

$w.onReady(() => {
   $w('#dataset1').onReady(() => {
      let startDate = // Fetch Value from dataset Column ; // Don't Know How to do!!
      let expiryDate = startDate + 547 *  86400000;
      $w("#dataset1").setFilter(wixData.filter()
      .between("invoiceDate" , startDate , expiryDate))
      .then(() => {
          console.log("Filtered!");
       })
     });
 });

Anyone??

Load more replies to check the last question.

@rinshulgoel
Perhaps this will work for you. Did not test it, so you surely will have to modify it…

//--------------------- User-Interface --------------------------------
 var DATASET = "dataset1"
 const REFERENCE = "invoiceDate"
 var dayCount = 547
 const dayFaktor = 86400000
//--------------------- User-Interface --------------------------------

$w.onReady(() => {
    $w('#'+DATASET).onReady(() => {
        $w('#'+DATASET).getItems(0, 5000)
        .then( (result) => {
 let items = result.items;
 let totalCount = result.totalCount;
            console.log(result)
            console.log(items)
            console.log(totalCount)
            console.log(items.invoiceDate)    
 
 let startDate = items.invoiceDate
 let expireDate = items.invoiceDate + dayCount * dayFaktor;
            console.log(startDate)
            console.log(expireDate)
 let filter =  wixData.filter()
 
 //filter = filter.gt(REFERENCE, expireDate);
            filter = filter.between(REFERENCE, startDate , expireDate))

            console.log(filter)

            $w('#'+DATASET).setFilter(filter)   
 
            .catch( (err) => {
 let errMsg = err.message;
 let errCode = err.code;
            });
        });
    });
 });

This is the end code-

import wixData from 'wix-data';

$w.onReady( () => {
  $w("#dataset1").onReady( () => {
    dateFilter();
  } );
} );

export function dateFilter(){

 const endDate = new Date();
 console.log(endDate)
 
 let startYear = endDate.getFullYear() - 1;
 let startMonth = endDate.getMonth() - 5;
 let startday = endDate.getDay() - 29;
 const startDate = new Date (startYear, startMonth, startday, 0, 0, 0);
 console.log(startDate);

 let yearValue = startDate.getFullYear();
 let monthValue = startDate.getMonth();
 let dayValue = startDate.getDate();
 let date1 = new Date (yearValue, monthValue, dayValue, 0, 0, 0);
 
 yearValue = endDate.getFullYear();
 monthValue = endDate.getMonth();
 dayValue = endDate.getDate();
 let date2=new Date (yearValue, monthValue, dayValue, 23, 59, 59);
 
   $w("#DATASETNAME").setFilter(wixData.filter()
   .between("REFERENCE",date1,date2))
   .then(() => {
     console.log("Filtered!");
   });
}