Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables not loading data after adding "sDom"

Im using DataTables (datatables.net) to display my data but when i add the sDom element, no data are loaded to the table.

The below code works

<script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#table_main').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "<?php echo base_url()?>datatable.php"

                });

            });
        </script>

although the tags are created that are given in the sDom, none of the data is loaded from he source. and also the button style which are given i fnInitComplete are not being applied

<script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#table_main').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "<?php echo base_url()?>datatable.php",
                    "sDom": "<'dtTop'<'dtShowPer'l><'dtFilter'f>><'dtTables't><'dtBottom'<'dtInfo'i><'dtPagination'p>>",
                         "fnInitComplete": function(){
                                $(".dtShowPer select").uniform();
                                $(".dtFilter input").addClass("simple_field").css({
                                    "width": "auto",
                                    "margin-left": "15px"
                            });
                         }

                });

            });
    </script>

any help on how to fix this error will be appreciated.

like image 838
LiveEn Avatar asked Jul 10 '26 22:07

LiveEn


1 Answers

At first, documentation says nothing about subclass insertion, so try from working start point with such code (replace same line):

"sDom": '<"dtShowPer"l><"dtFilter"f><"dtTables">rt<"dtBottom"><"dtInfo"i><"dtPagination"p>',

I dont have any code example with data (but u can provide some on pastebin.com or else), and code seems correct. So just add one rule in sDom and add one-by-one after checking if it works fine.

like image 109
StasGrin Avatar answered Jul 13 '26 13:07

StasGrin