How to show the empty message on html table on json array empty .
i have tried the bellow code its donesnt work
if (isEmpty(jsonvalue) == true)
{
console.log("len 0 called");
$('#tablex').dataTable({
"language": {
"emptyTable": "No data available in table"
}
});
$('#tablex').empty("Test");
}
Thanks in advance ,
Karthik.K

Daniel WrightPosted Apr 29, 2025, 1:59 AM
It seems like you are trying to display a message in the HTML table if the JSON array is empty. Your code snippet appears to be attempting this functionality. Here are a few suggestions to help you troubleshoot and potentially enhance the implementation:
1. Check isEmpty Function: Ensure that the `isEmpty` function is correctly implemented and properly validates whether the `jsonvalue` is empty. If this function is not defined in your code snippet, you may need to create it or use an alternative method to check if the JSON array is empty.
2. Use of Datatable Library: If you are using the Datatable library to render your table, make sure that it is initialized correctly and that the necessary configurations, such as the language settings for `emptyTable`, are properly set.
3. Empty Table Content: The `empty` function in jQuery is used to remove all child nodes of the selected element. If you intend to display a message when the table is empty, consider updating the content of the table instead of emptying it completely. You can manipulate the table content to show your custom message when the JSON array is empty.
4. Conditional Rendering: Instead of emptying the table and trying to display a message simultaneously, you can conditionally check if the JSON array is empty and then dynamically update the table content to either show the data or the custom message.
Here's a basic example:
By following these suggestions and ensuring that your functions are correctly implemented, you should be able to display the desired message in the HTML table when the JSON array is empty. If you encounter any specific issues or need further assistance, feel free to provide more details for additional help. Good luck with your implementation!