Combine to functions in javascript

Combine to functions in javascript

KarlheinzKarlheinz Posts: 2Questions: 1Answers: 0

Hi everyone,

I try to combine to functions in javascript to work with datatables, but it doesn't work. How can I combine both functions in Javascript so that they both work?

$(document).ready(function() {
    $('#cx_data').DataTable( {
        order: [[ 2, 'desc' ], [ 0, 'asc' ]],
        "ordering": false,
        "language": {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json",

        }

    } );
} );

and

$(document).ready(function() {
    $('#cx_data').DataTable( {
        "createdRow": function ( row, data, index ) {
            if ( data[5].replace(/[\$,]/g, '') * 1 > 150000 ) {
                $('td', row).eq(5).addClass('highlight');
            }
        }
    } );
} );

Every hint is appreciated. I've already spent hours trying to figure it out, but without success.

Thank you
Karlheinz

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    Answer ✓

    When you say they don[t work what does that mean? Please describe specifically what happens.

    Do you get any error messages (alert or browser console)?

    I suspect you are getting a syntax error because you are missing a comma that is needed to separate the parameters, ie, between createdRow and the other parameters. Something like this:

    $(document).ready(function() {
        $('#cx_data').DataTable( {
            order: [[ 2, 'desc' ], [ 0, 'asc' ]],
            "ordering": false,
            "language": {
                "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json",
     
            },  //do you have this comma?
            "createdRow": function ( row, data, index ) {
                if ( data[5].replace(/[\$,]/g, '') * 1 > 150000 ) {
                    $('td', row).eq(5).addClass('highlight');
                }
            }
     
        } );
    } );
    

    Kevin

  • KarlheinzKarlheinz Posts: 2Questions: 1Answers: 0

    That was it. A simple comma. :s
    Thank you very much, Kevin! :)

This discussion has been closed.