≡

Got stuck with Custom content at ColumnControl

Got stuck with Custom content at ColumnControl

WernfriedWernfried Posts: 61Questions: 14Answers: 0

I try to use my own datepicker as shown in Custom content - Built-in helpers because user ask to filter on date ranges.
I made good progress, but now I got stuck with Server-side processing.

DataTable.ColumnControl.content.dateRangePicker = {
  init: function (config) {
     const dt = this.dt();
     const idx = this.idx();
     const searchInput = new DataTable.ColumnControl.SearchInput(dt, idx, idx);
     searchInput.element().querySelectorAll('.dtcc-search-type-icon, .dtcc-search-icon').forEach(el => el.remove());
     searchInput.element().querySelector('.dtcc-search select').classList.add('is-hidden');
     searchInput.element().querySelector('.dtcc-search select').add(new Option('contains', 'contains', true, true));

     const picker = daterangepicker(
        searchInput.input(),
        {
           startDate: null,
           endDate: null,
           minDate: DateTime.now().startOf('month').minus({ years: 5 }),
           maxDate: DateTime.now().endOf('month').plus({ years: 1 }),
           onOutsideClick: 'cancel',
           singleMonthView: true,
           autoApply: true,
           locale: {
              format: DateTime.DATE_MED
           }
        },
        (startDate, endDate) => {
           console.log(startDate.toISO(), endDate.toISO());
           searchInput.element().classList.add('dtcc-search_active');
           searchInput.set('contains', startDate.toISO());
        }
     );
     picker.addEventListener('show', () => {
        // Prevent that daterangepicker is closed by DataTables when selecting month
        picker.container.querySelector('.prev').addEventListener('click', (ev) => { ev.stopPropagation(); }, true);
        picker.container.querySelector('.next').addEventListener('click', (ev) => { ev.stopPropagation(); }, true);
     })
     return searchInput.element();
  }
};

How do I trigger the ajax call to my server? I would expect searchInput.set(...) may trigger it, but it does not. I tried runSearch() and search() but runSearch(true) fails with

Uncaught TypeError: this._search is not a function

Can you help me?
Wernfried

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 66,182Questions: 1Answers: 11,040 Site admin
    Answer ✓

    The SearchInput class has an sspData() method which can be used to set the extra information needed to submit to the server.

    There is [an example of it used here, although there it is static, rather than dynamic. You could set that in your callback function.

    The other option is to combine the start and end times into a single string value, and then separate them at the server-side.

    Date range is definitely something I'd like to look at adding for ColumnControl.

    Allan

  • WernfriedWernfried Posts: 61Questions: 14Answers: 0

    The problem is not the data content to be sent. I don't know how to trigger the actual submit. But now I found it out, I simply have to run dt.draw()

  • allanallan Posts: 66,182Questions: 1Answers: 11,040 Site admin
    Answer ✓

    Oh I see, sorry I misunderstood. Yes, when server-side processing, the data will be sent and the draw updated when a draw happens, so a fresh draw is the correct way to do it.

    Allan

Sign In or Register to comment.