Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle database null values in jquery datatable

I have a jquery datatable with the data coming from database,fetched from java servlet.Few columns have null values.Because of this i am getting warning like

DataTables warning: table id=lplist - Requested unknown parameter 'FeeCompany' for row 9. For more information about this error, please see http://datatables.net/tn/4

I want those null values to be replaced by empty string.Can someone please guide how to achieve this.

My code snippet is as below

    <script
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script
    src="http://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>

<script
    src="http://cdn.datatables.net/scroller/1.2.2/js/dataTables.scroller.min.js"></script>
<link
    href="http://cdn.datatables.net/scroller/1.2.2/css/dataTables.scroller.css"
    rel="stylesheet" type="text/css" />

<link href="http://cdn.datatables.net/1.10.4/css/jquery.dataTables.css"
    rel="stylesheet" type="text/css" />
<title>Insert title here</title>
<script type="text/javascript">
            $(document).ready(function () {
                $("#lplist").dataTable({
                    "serverSide": true,
                    "sAjaxSource": "/JQueryDataTablesAll/CompanyGsonObjects",

                    dom: "rtiS",
                    scrollY: 450,
                    scrollX:true,
                    "processing": true,                     
                    "aoColumns": [
                                  { "mData": "InsuredName" },
                                  { "mData": "CustAddress_City" },
                                  { "mData": "CustAddress_State" },
                                  { "mData": "CustAddress_Zip" },
                                  { "mData": "CustSurvey_Location" },
                                  { "mData": "PolicyNo" },
                                  { "mData": "ProfitCenter" },
                                  { "mData": "FeeCompany" }, 

                              ]



                });
            });
        </script>
</head>
<body id="dt_example">
    <div id="container">
        <div id="links">
            Server-side processing with object source <br />
        </div>
        <div id="demo_jui">
            <table id="lplist" class="display">
                <thead>
                    <tr>
                        <th>Insured Name</th>
                        <th>City</th>
                        <th>State</th>
                        <th>Zip</th>
                        <th>Survey Location</th>
                        <th>PolicyNo</th>
                        <th>Profit Center</th>
                        <th>Fee Company</th>                        

                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>

    </div>
like image 892
xdev Avatar asked Dec 16 '14 10:12

xdev


Video Answer


1 Answers

Add defaultContent in the options while initializing the data table. For more details

columns.defaultContent

Example from the official documentation:

$('#example').dataTable( {
  "columns": [
    null,
    null,
    null,
    {
      "data": "first_name", // can be null or undefined
      "defaultContent": "<i>Not set</i>"
    }
  ]
} );
like image 135
shailb Avatar answered Oct 02 '22 13:10

shailb