Multi render, renderer

Multi render, renderer

rduncecbrduncecb Posts: 125Questions: 2Answers: 28

Here's a quick 'multi render' renderer for anyone that may want it.
The render function:

    $.fn.dataTable.render.multi = function(renderArray) {
        return function(d, type, row, meta) {
            for(var r = 0; r < renderArray.length; r++) {
                d = renderArray[r](d, type, row, meta);
            }

            return d;
        }
    }

Here's how to use it in a column definition, a simple array of the normal renderers

                        render: $.fn.dataTable.render.multi(
                        [
                            $.fn.dataTable.render.moment('YYYY-MM-DDTHH:mmZ', 'DD-MMM-YYYY'),
                            $.fn.dataTable.render.substring(3, 6),
                            $.fn.dataTable.render.toUpperCase()
                        ])

The example is rather contrived purely to demonstrate using multiple renderers so please don't comment that I could have simply supplied a different date format to the moment renderer ;)
The other two renderers are custom and do pretty much what they say on the tin.

Each render is called in turn, the return value of each render being fed to the next.

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Very clever! Nice one - thanks for sharing it with us!

    Allan

This discussion has been closed.