Problems when updating from SearchBuilder 1.0.1 to 1.1.0

Problems when updating from SearchBuilder 1.0.1 to 1.1.0

schwaluckschwaluck Posts: 103Questions: 27Answers: 1

Hi,

I wanted to upgrade my SearchBuilder Version to 1.1.0.
In the patch notes I saw that it is required to load the DateTime now seperately, which is no problem at all.

The new version works fine, however I have this code here, which basically pre-filles and directly filters the table whenever someone selects the "between" method for a date.
I am also using moment for that.

The whole setup works perfectly with SearchBuilder 1.0.1, but not at all with 1.1.0.
It wont do a search and after trying to manually select another date, it is not in a moment format anymore. However, it is also not searching.

Is there any change from 1.0.1 to 1.1.0 in the SearchBuilder that is breaking this?

Code:

{
                extend: 'searchBuilder',
                    config: {
                        columns: [1,7,8,11],
                        conditions: {
                            "moment":{
                                    '=': null,
                                    '!null': null,
                                    '<': {
                                        conditionName: 'vor',
                                        },
                                    '!=': null,
                                    '>': {
                                        conditionName: 'nach',
                                        },
                                    'between': {
                                        init: function(that, fn, preDefined = null) {
                                        // Declare all of the date elements that are required using DataTables dateTime plugin
                                        let els = [
                                            $('<input/>')
                                                .addClass("dtsb-value")
                                                .addClass("dtsb-input")
                                                .dtDateTime({
                                                    attachTo: 'input',
                                                    format: that.s.momentFormat ? that.s.momentFormat : undefined
                                                })
                                                .on('input change', function() { fn(that, this); }),
                                            $('<span>')
                                                .addClass(that.classes.joiner)
                                                .text('and'),
                                            $('<input/>')
                                                .addClass("dtsb-value")
                                                .addClass("dtsb-input")
                                                .dtDateTime({
                                                    attachTo: 'input',
                                                    format: that.s.momentFormat ? that.s.momentFormat : undefined
                                                })
                                                .on('input change', function() { fn(that, this); })
                                        ];

                                        // If there are and preDefined values then add them
                                        if (preDefined !== null && preDefined.length > 0) {
                                            $(els[0]).val(preDefined[0]);
                                            $(els[2]).val(preDefined[1]);
                                        }
                                        else {
                                            var today = moment().format("DD.MM.YY");
                                            $(els[0]).val(today);
                                            $(els[2]).val(today);
                                        }
                                        
                                        that.s.value = [today, today];
                                        return els;
                                    },
                                        conditionName: 'zwischen',
                                        },
                                    '!between': null,
                                    'null': null,
                                    }
                        },
                    },
            },

I would be very thankful for any input! :)

Thanks a lot.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Are you able to give me a link to a test case and I'll see if I can trace it through to understand why that isn't working please?

    Thanks,
    Allan

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    Hi Allan,

    I modified the test case Sandy created a while back for me as a response:
    http://live.datatables.net/yoculawi/15/edit

    I simply added the 1.1.0 verison and loaded the DateTime ontop.
    However, if you select between now, it won't do the searching right away and also, if you click on a date again, it's not in the right format.

    Hopefully this makes sense and thanks a lot already! :)

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Answer ✓

    Got it - many thanks for that :).

    We renamed the internal parameter momentFormat to be dateFormat. Changing that in your code allows it to work again: http://live.datatables.net/yoculawi/17/edit .

    Allan

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    Many thanks for the answer - this actually solved a lot of headache for me!
    Now I can use searchBuilder serverside as well since I thought he problem was related to that one, haha.

    Again, many thanks!

    Have a nice day!

Sign In or Register to comment.