col.sTitle.replace is not a function

col.sTitle.replace is not a function

prasadnadendlaprasadnadendla Posts: 2Questions: 1Answers: 0

I am using title of type function instead of string. It throws the above error during sorting.

Using latest version of data-tables.net package along with the licensed version of editor

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Happy to take a look at a test case showing the issue so I can help resolve it or patch DataTables if needed.

    Allan

  • prasadnadendlaprasadnadendla Posts: 2Questions: 1Answers: 0

    @allan Thank you for your prompt response. After examining the source, it appears that there is no logic to perform type checking before treating it as a string replacement.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    edited August 2023

    I put together this little example, and yes I see the issue. However, columns.title does document that it should be given as a string. If you are passing in a number, add .toString() after the number or just + '' and it should work as expected.

    edit Sorry - you are using a function. Yes, that isn't supported at all for the title. You'll need to execute the function at initialisation time to get the value (a string).

    Allan

  • prasadnadendlaprasadnadendla Posts: 2Questions: 1Answers: 0

    Thanks @allan. Certainly, I understand now. Apologies for the confusion, as I initially thought it supported function types. Could you please guide me on how to add a custom element to the header without it being affected by the sorting click?

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Put your span, or whatever tag you want into the header and then stop the event from bubbling. Here is a little example.

    Allan

Sign In or Register to comment.