11

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>

3 Answers 3

14

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>"
    }
  ]
} );
Sign up to request clarification or add additional context in comments.

Comments

5

You can use mRender to specify the display in the event of a null value:

{ 
    "mData": "FeeCompany" 
    'mRender': function (data, type, full) {
        if (full[7] !== null) {
             return full[7]; 
         }else{
             return '';
         }
},

Comments

0
{

  "data": function(data, type, dataToSet) {

    return data.CourseEducator1 ? ? " " + "<br/>" + data.CourseEducator2 ? ? ";

  }

}

1 Comment

when we want to return more than one data in a column, a block of code that shows blank instead of null if there is empty space

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.