Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82400

Question regarding: Row created callback

$
0
0

I'd like to change the text color of a cell (if possible) based on a condition. For example, if a date is prior to today's date, I'd like to highlight the text in red similar to what is done at this page.

No matter where I place the code within my existing code below, I cause an error. Can anyone tell me if I'm able to achieve what I'd like above and if so, where should I insert the code from the page above?

Code snippet from page above:

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

My existing code:

            var assignmentTable = $('#job_assignments').DataTable( {
                "iDisplayLength": 12,
                dom: "Bfrtip",
                ajax: {
                    url: 'assignments2.php',
                    type: 'post',
                    data: (function ( d ) {

                        var selected = jobTable.row( { selected: true } );

                        if (selected.any() ) {

                            d.job_id = selected.data().jobs.job_id;

                        }
                    })
                },

                columns: [
                    { data: "job_assignments.job_id" },
                    { data: "jobs.job_number" },
                    { data: "job_assignments.component" },
                    { data: "job_assignments.colors" },
                    { data: "job_assignments.quantity" },
                    { data: "job_assignments.production_date" },
                    { data: "job_assignments.machine_id" },
                    { data: "machines.machine_name" },
                    { data: "job_assignments.is_completed" }
                ],

                columnDefs: [
                    {
                        // The `data` parameter refers to the data for the cell (defined by the
                        // `data` option, which defaults to the column being worked with, in
                        // this case `data: 0`.
                        "render": function ( data, type, row ) {
//                          return data +' - ('+ row.machines.machine_name+')';
                            return ''+ row.machines.machine_name +'';
                        },
                        "targets": 6
                    },
                    { "visible": false,  "targets": [ 0, 7 ] }
                ],

//              select: true,
                select: {

                    style: 'single'
                },

                buttons: [
//                  { extend: "create", editor: assignmentEditor },
                    {
                        extend: "edit",   editor: assignmentEditor.disable(['jobs.job_number', 'job_assignments.component'])
                    },

                    {
                        extend: "selectedSingle",
                        text: "Add Job Component",

                            action: function ( e, dt, node, config ) {
                                var rowData = dt.row( { selected: true } ).data();
                                window.open( ' component_form_create.php?job_id='+rowData.job_assignments.job_id, '_self' );
                            }

                    },

                    {
                        extend: "remove",
                        editor: assignmentEditor,
                        formMessage: function ( e, dt ) {
//                          var rows = dt.rows( e.modifier() ).data().pluck('jobs.job_name');
                            var rows = dt.rows( e.modifier() ).data().map( function ( o ) {
                                return o.job_assignments.component;
                            } );
                            return 'Are you sure you want to permanently delete this job component? <ul><li>'+rows.join('</li><li>')+'</li></ul>';
                        }
                    }


                ]
            } );

Viewing all articles
Browse latest Browse all 82400

Trending Articles