Custom render type

Custom render type

seligeselige Posts: 2Questions: 1Answers: 0
edited April 2020 in Free community support

Hi there,

I needed to define a render based on the type and I've seen these two discussions ( https://datatables.net/forums/discussion/23849/custom-rendering-in-plugins-for-custom-data-types,
https://datatables.net/forums/discussion/23281/create-custom-type).
Is it currently available or should it be done through $ .fn.dataTable.render.customType ()?

Thank you

Answers

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

    I don't quite follow the question, but you can create your own renderers - see other examples here.

    Colin

  • seligeselige Posts: 2Questions: 1Answers: 0

    Hi,

    I know I can do this:

    $.fn.dataTable.render.customString = function () {
        return function ( data, type, row ) {
            if ( type === 'display' ) {
                if (data == 'a'){
                    return 'b';
                }else{
                    return 'c';
                }
            }
            return data;
        };
    };
    
    {
        data: 'description',
        render: $.fn.dataTable.render.customString()
    }
    

    But my question is if is it possible make something like this:

    $.fn.dataTable.render.customString = function () {
        return function ( data, type, row ) {
            if ( type === 'display' ) {
                if (data == 'a'){
                    return 'b';
                }else{
                    return 'c';
                }
            }
            return data;
        };
    };
    
    {
        data: 'description',
        type: 'customString'
    }
    

    Thank you

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

    I think the type if for internal types only - you would need to do what you were doing in the top code block.

    Colin

This discussion has been closed.