render function show NaN.N for null values

render function show NaN.N for null values

SebastianRMSebastianRM Posts: 1Questions: 1Answers: 0

Hi everyone! I have on my controller this method:

public function index_data()
    $productos = Product::with('category')
                        ->with('product_canals')->orderBy('name', 'ASC');

    return DataTables::eloquent($productos)->addColumn('prices',function (Product $product) {
                                return $product->product_canals->map(function($product_canal) {
                                    if($product_canal->canal->id == 1)
                                        return $product_canal->price;


And on the view I have this:

$(function() {
        processing: true,
        serverSide: true,
        ajax: '{!! route('products_datatable') !!}',
        columns: [
            { data: 'name', name: '' },
            { data: '', name: '' },
            { data: 'prices', name: 'prices', render: $.fn.dataTable.render.number( ',', '.', 2, '$ ' ) },

But the result for null value on price column show $ NaN.N

(see attached file)

Can you help me?


  • colincolin Posts: 3,617Questions: 0Answers: 636

    Hi @SebastianRM ,

    My guess is that server isn't sending your expected data for those rows. If you remove the columns.render function, what does it display what you would expect?

    If that doesn't help, we're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.



Sign In or Register to comment.