How to show "No data available in table" or "No data available in table" If no data exist

How to show "No data available in table" or "No data available in table" If no data exist

mrbillonesmrbillones Posts: 3Questions: 1Answers: 0
edited August 2017 in Free community support

Hi All!

Good day! I would like to seek for your assistance regarding my issue in datatable. Im trying to execute a datatable with no existing data but it shows this error:

DataTables warning (table id = 'DataTables_Table_0'): Requested unknown parameter '0' from the data source for row 0

how can i show "No data available in table" or "No data available in table" if the the datatable show empty table or data? and Which of the two .JS should i change? Please see the code below. Many Thanks!

front-end code(PHP-MYSQL):

<?php
                                    
                                    include('config.php');
                                    $sql = "SELECT * FROM opt_project_tracker where ID = 'XXX'";
                                    $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
                                    while($rows=mysql_fetch_array($result)){
                                    ?>
                            <td align="left"><a href="form3.php?id=<?php echo $rows['ID']; ?>"><?php echo $rows['RRF_ID']; ?></a></td>
                            <td align="left"><?php echo $rows['Project_Name']; ?></td>
                            <td align="left"><?php echo $rows['Specialist_Assigned']; ?></td>

                                                <td class="center">                                                
                                                <div class="controls center">
                                                    <a href="<?php echo $rows['ID']; ?>" title="Edit task" class="tip"><span class="icon12 icomoon-icon-pencil"></span></a>
                                                    <a href="<?php echo $rows['ID']; ?>" title="Remove task" class="tip"><span class="icon12 icomoon-icon-remove"></span></a>
                                               </div>
                                               </td>
                                            </tr>
                                            <?php
                                            };
                                            ?>
                                        </tbody>
Datatable.js:
/* Table initialisation */
$(document).ready(function() {
    $('#example').dataTable( {
        "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page"
        }
    } );
} );


datatable.min.js:
$(document).ready(function() {
    $('#example').dataTable({
        "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page"
        }
    })
});

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    Can you do a View source in your browser when there are no rows in the HTML (i.e. when the error happens) and show me the generated HTML for the table please?

    Thanks,
    Allan

  • mrbillonesmrbillones Posts: 3Questions: 1Answers: 0
    edited August 2017

    Hi Sir,

    Good day! This is the generated table where the error encountered. Thank you.

    <div class="row">
                            <div class="col-lg-12">
                                <div class="panel panel-default gradient">
                                    <div class="panel-heading">
                                        <h4>
                                            <span>Data table</span>
                                        </h4>
                                    </div>
                                    <div class="panel-body noPad clearfix">
                                        <table cellpadding="0" cellspacing="0" border="0" class="dynamicTable display table table-bordered" width="100%">
                                            <thead>
                                                <tr>
                                                    <th>RRF ID</th>
                                                    <th>Project Name</th>
                                                    <th>Specialist</th>
                                                    <th>Details</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                                                </tbody>
                                            <tfoot>
                                                <tr>
                                                    <th>RRF ID</th>
                                                    <th>Project Name</th>
                                                    <th>Specialist</th>
                                                    <th>Details</th>
    
                                                </tr>
                                            </tfoot>
                                        </table>
                                    </div>
    
                                </div><!-- End .panel -->
    
                            </div><!-- End .span12 -->
    
                        </div><!-- End .row -->         
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    You have an empty tr in the tbody which is causing the issue. Remove that and the issue will be resolved.

    Allan

  • mrbillonesmrbillones Posts: 3Questions: 1Answers: 0

    There is a PHP in it, if I remove that, it will not show the php mysql result. I am searching where I can customize the value of input text where I will replace it will some variables

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    It looks like your opening tr isn't inside the while loop for reading and outputting the database read data.

    Allan

This discussion has been closed.