Using responsive details display leads to error "Uncaught TypeError: g.display is not a function"

Using responsive details display leads to error "Uncaught TypeError: g.display is not a function"

Benku21Benku21 Posts: 3Questions: 1Answers: 0

Hi,

Unfortunately, I couldn't find any subject to help me resolve my problem. So here I go:

I am using DataTables last release 1.10.22 and the extensions "Responsive" v.2,2.6. That's how I load them:

I saw on some questions that loading multiple jQuery files could lead to a problem. But there again, I only load it once as you can see here:

The error happens every time I use the display property of the details object. If i'm not using it, no error :

'responsive': {
'details': {
'display': "function() { $.fn.dataTable.Responsive.display.modal() }",
}
},

the value of display could be empty, true, false or whatever, i get this error :

I thought that this issue was fixed, it looked the same as mine https://github.com/DataTables/Responsive/issues/61. Is that really a problem ? Or just in my case ? I don't think it's necessary to show you my files because it seems to be a problem with the source files or my jquery version.

I'm open to any solutions. Thanks.

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited October 2020

    You have this:

    'display': "function() { $.fn.dataTable.Responsive.display.modal() }",
    

    The " around the function need to be removed. You want a Javascript function as the option not a string. See this example:
    https://datatables.net/extensions/responsive/examples/display-types/modal.html

    Kevin

  • Benku21Benku21 Posts: 3Questions: 1Answers: 0
    edited October 2020

    @kthorngren that's a good point but in my case I'm using Datatables with twig. So it's a method from twig which call datatables method but same parameters are used. So if I don't use quotes, I get an error like 'Unexpected character $'. And if for example I set 'display' to '' or false (with or without quotes), I get "g.display is not a function'.

    Also, I get the same error if i set details.renderer : 'g.renderer is not a function'. It's really strange... If I set details.type details.column, no problem.

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    in my case I'm using Datatables with twig

    I'm not familiar with twig. Sounds like you are trying to use twig to generate the Datatables Javascript code. Twig will need a way to generate a Javascript function. If this is what you are doing then you will need to refer to the Twig documentation or support to find out how to do this.

    Kevin

  • Benku21Benku21 Posts: 3Questions: 1Answers: 0

    Yes it's a bit like that. Looking at the error, I thought that maybe something was wrong with the js files, but I don't think everyone has this problem. I'll check that. Thanks anyways :)

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    You might need to escape the $ in the Twig file, but it has been years since I last used it - you might need to ask on SO or a Twig specific forum.

    Allan

This discussion has been closed.