KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dashboard + DataTables + rowCallback #2342

Open Mathieu Viennet opened this topic on on Sep 16, 2021 - 5 comments

Mathieu Viennet commented on Sep 16, 2021

Hi,

i'm using Datables and the Dashboard. But i can't seem to get rowCallback to work. Maybe i put it in the wrong palce?

Here's my code, thanks for helping :

    protected function onCreated()
    {
        $this
        ->use(\koolreport\datagrid\DataTables::class)
        ->settings([
            "options"=>array(
                "paging"=>true,
                "searching"=>true,
                "pageLength"=> 50,                   
            ),            
			"columns"=>array(
            "product_name"=>array(
	            "label"=>"Product Name"
            ),
            "_stock"=>array(
	            "label"=>"Current Stock"
            ),
            "_qty"=>array(
	            "label"=>"Quantity sold"
            ),
            "_line_total"=>array(
            	"label"=>"Sales Amount",
				"type"=>"number",
				"prefix"=>"$",
				"decimals"=>2,
        ),
            "_inc_product_status"=>array(
	            "label"=>"Status"
            )),
		
		"rowCallback"=> "function( row, data ) {
							if ( data['_inc_product_status'] == 'Discontinued' ) {        
								$(row).addClass('yellow');
								$(row).find('td').addClass('yellow');
	         				}
			 				else if ( data['_inc_product_status'] == 'DiscontinuedRA' ){
			 					$(row).addClass('red');
			 					$(row).find('td').addClass('red');
	       					}
    					}"      

        ]);
    }
KoolReport commented on Sep 17, 2021

Hi Mathieu,

I suggest that you use koolreport\dashboard\widgets\Table as it is dashboard-native widget (without using KWidget). If the issue is just that you want to change color of cells according to value, you can use Badge fields inside Table.

Please look at our extra columns section in Table example.

Hope that helps.

Mathieu Viennet commented on Sep 17, 2021

Hi,

I need to use DataTables...if i can't use a simple function inside DataTables with the Dashboard (which is disapointing)...do you suggest that i switch to the "normal" KoolReport Pro?

Thanks,

KoolReport commented on Sep 17, 2021

Oh, of course that you can use DataTables, I just recommend a simpler solution with Table, but if all you need is DataTables then use it. So the issue is that there is no response from rowCallback, and you do not see any update to the cell of datatables.

Mathieu Viennet commented on Sep 17, 2021

Hi,

yes that is my problem. The function that you see in my code works on another website with the "original" datatables.

If i put Rowcallback inside the options ( ->settings(["options"=>array( i do see the function on the page Source (but no CSS class is added to the row). If i put it outside the options, i see nothing in the source code.

Thanks,

Sebastian Morales commented on Sep 20, 2021

Mathieu, the "rowCallback" options should be inside "options" property of DataTables like this:

    DataTables::create(array(
        ...
        "options" => array(
            ...
            "rowCallback" => ...
    ));

Let us know if this works for you or not. Tks,

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

Dashboard