szakendre

szakendre

szakendreszakendre Posts: 24Questions: 10Answers: 0
edited January 2023 in DataTables

Hi!

I'm using DT 1.11.5, but my problem appears with other versions too.

I want to use URL search and stateSave together.

        $.urlParam = function(name)
        {
            var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);

            if (!results)
            {
                return '';
            }
            return results[1] || '';
        }

            "oSearch":
            {
                "sSearch": $.urlParam('search')
            },

When I turn the stateSave on, the URL search doesn't work with Firefox 109.0 and older versions too, and Chrome 109.

Does anybody have an idea how to solve this, or a workaround maybe?

Thank you and have a nice day!

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • szakendreszakendre Posts: 24Questions: 10Answers: 0

    Dear Colin,

    Unfortunately, I was not able to prepare any test cases.

    But I just found a solution, or workarouind:

    function getUrlParameter(name)
    {
        name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
        var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
        var results = regex.exec(location.search);
        console.log(decodeURIComponent(results[1].replace(/\+/g, ' ')));
        return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
    }
    

    and

    table1.search(getUrlParameter('search')).draw();
    

    Best regards:
    Endre, Szak

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Nice, thanks for reporting back!

    Colin

Sign In or Register to comment.