When datatables returns results that are empty, the "datatables_empty" class doesn't get added

When datatables returns results that are empty, the "datatables_empty" class doesn't get added

eshanseshans Posts: 11Questions: 3Answers: 0

Hi all - weird problem. Sometimes the datatables_empty class gets applied when there's no results but other times it doesn't. Is there a way to write code to say if the results are empty, add this class (with the required colspan)? Thank you. The image is below.

This question has an accepted answers - jump to answer

Answers

  • eshanseshans Posts: 11Questions: 3Answers: 0

    Sorry this is the code that renders the table

    if (!orderSearchDTO) {
      orderSearchDTO = $orderTable.DataTable({
        destroy:true,
        data:theData,
        columns:ordersMap,
        order:sortArray,
        autoWidth:false,
        paging:false,
        dom:'ft',
        searching: false
      });
    } else {
      orderSearchDTO.clear();
      orderSearchDTO.rows.add(theData);
      orderSearchDTO.draw();
    }
    ax.Tables.responsify($orderTable);
    OrdersPVM.isLoading(false);
    
    $allOrders.show();
    };
    
  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin
    Answer ✓

    Can you link to a page showing the issue so I can understand why this is happening and offer some help with solving it please. It isn't an issue I've come across before that I can recall.

    Allan

  • eshanseshans Posts: 11Questions: 3Answers: 0

    Thanks Allan - it's a site in development so I can't really post it publicly unfortunately. Sorry

  • eshanseshans Posts: 11Questions: 3Answers: 0

    Also, is there a way to just check to see if the data coming back is empty and if so, just apply the empty class?

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin

    DataTables should do so. Can you show me the data that is being returned?

    Allan

  • eshanseshans Posts: 11Questions: 3Answers: 0

    Here's the firebug screenshot

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin

    theData is data.results from the JSON? That should work okay.

    Allan

  • eshanseshans Posts: 11Questions: 3Answers: 0

    It is, yes. Thanks, I don't know what's going on here. haha

  • eshanseshans Posts: 11Questions: 3Answers: 0

    Hey allan, here's a screenshot of the markup. Could it be anything to do with knockout.js?

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin

    Very possibly - without being able to debug the page it is very difficult to say. Due to the lack of colspan and class information, it would appear that the row being written in the tbody is not being created by DataTables. Perhaps it is being created by something else, which is where the problem would be.

    Allan

  • eshanseshans Posts: 11Questions: 3Answers: 0

    ok thanks. it's definitely DT creating it just (the above code) but maybe something else is interfering with it

This discussion has been closed.