How to use multiple renderers?

How to use multiple renderers?

Link to test case: http://live.datatables.net/bufafegi/1/edit

Error messages shown: Uncaught TypeError: renderArray[r] is not a function

Description of problem: To use multiple renderers I followed this nice post. However my test case returns the aforementioned error.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    The primary issue is that you were using $.fn.dataTable.render.colorNegative(), but $.fn.dataTable.render.colorNegative is in fact the renderer, so that should be passed in - not executed.

    But more than that, the multi renderer wasn't quite right - since renderers can contain objects, allowing different functions per type, with a _ property as fallback. Here is your test case updated to address both of them: http://live.datatables.net/bufafegi/3/edit .

    I'm wondering if we should include the multi renderer in DataTables core...

    Allan

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Sorry - my last change wasn't quite complete - here is the working version: http://live.datatables.net/bufafegi/4/edit .

    Allan

  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0

    Thanks Allan for this quality answer and working solution.

    I'm wondering if we should include the multi renderer in DataTables core...

    Since it allows to split big specific renderers to smaller and reusable ones, which is a good practice, I think it's a good idea. Also, it might be easier for the user to find the related doc as a reference instead of searching on the web to find this post.

    If you're hesitating for core, may be plugins could be the right place for it.

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Yes, I think short term it should probably go into the plug-ins, and then I'll think about it for v2 :).

    Thanks!
    Allan

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0

    Cool! Thanks Allan :)

This discussion has been closed.