I don't see columns during rendering datatables - serverside,processing

I don't see columns during rendering datatables - serverside,processing

SakullSakull Posts: 5Questions: 1Answers: 0
edited October 2019 in Free community support

I'm done server-side programming.
"processing": true,
"serverSide": true,
This is great for me.

Right now when I render tables using <th>, I don't see any columns <th></th>, only those declared in the code javascript.

array( 'db' => 'as_name', 'dt' => 2 ), 
array( 'db' => 'as_cat_name',  'dt' => 3 ), 
array( 'db' => 'as_producent', 'dt' => 4 ), 

I think datatables overwrites my settings.
How to create mix colums in datatables ?

<script>
            $(document).ready(function() {
             $('#xyz_akcesoria_dTable').DataTable( {
        
        //"responsive": true,       
        "processing": true,
        "serverSide": true,
        "ajax": "xyz.php",
        
        //2,3,4 - visible 
        "columnDefs": [
        {
                "targets": [ 0 ],
                "visible": false,
                "searchable": false
            },
            {
                "targets": [ 1 ],
                "visible": false,
                "searchable": false
            },
            {
                "targets": [ 5 ],
                "visible": false,
                "searchable": false
            },
            {
                "targets": [ 6 ],
                "visible": false,
                "searchable": false
            },
            {
                "targets": [ 7 ],
                "visible": false,
                "searchable": false
            },
            {
                "targets": [ 8 ],
                "visible": false,
                "searchable": false
            }           
        ]
        
                
                } );
                 } );
           
        </script>
            <table id="xyz_akces_dTable" class="table table-striped table-hover">
                <thead>
                    <th></th>           <!-- number - I DON'T SEE -->
                    <th>name</th>                   <!-- array( 'db' => 'as_name', 'dt' => 2 ), -->
                <th>type</th>                   <!-- array( 'db' => 'as_cat_name',  'dt' => 3 ), -->
                    <th>producent</th>                      <!-- array( 'db' => 'as_producent', 'dt' => 4 ), -->
                    <th>amount</th>    <!-- amount - I DON'T SEE -->
                    <th></th>           <!-- other data - I DON'T SEE button -->
                </thead>
                <tbody>

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

Replies

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    edited October 2019

    You have "visible": false, set for columns 0, 1, 5, 6, 7, 8. If you want them visible either remove the line or set it to true. Also it looks like you have 6 columns defined in your HTML but your columnDefs is configured for 9 columns. The need to match. You are probably getting Javascript errors that you can see in the browser's console.

    Additionally if you are doing the same config options with multiple columns you can set columnDefs.targets to an array, like this:

            "columnDefs": [
            {
                    "targets": [ 0, 1, 5, 6, 7, 8 ],
                    "visible": false,
                    "searchable": false
                },
            ],
    

    Kevin

  • SakullSakull Posts: 5Questions: 1Answers: 0

    I don't know if you understand my issue.

    Is possible show mix tables, HTML and data from database via datatables ?

    <thead>
    <th>A</th> <!-- I don't want to see data from database -->
    <th>name</th> <!-- OK array( 'db' => 'as_name', 'dt' => 2 ), -->
    <th>type</th> <!-- OK array( 'db' => 'as_cat_name', 'dt' => 3 ), -->
    <th>producent</th> <!-- OK array( 'db' => 'as_producent', 'dt' => 4 ), -->
    <th>E</th> <!-- I don't want to see data from database -->
    <th>F</th> <!-- I don't want to see data from database -->
    </thead>

    During rendering 2 second is OK

    after 2 seconds the tables are filled with data from datatables

    It's NO OK

    I would like A,E,F columns rendering without data from JS datatables

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    If I understand correctly you have an HTML based table. Then when using server side processing the HTML table is removed and replaced by the server side processing data. Is this your question?

    You can see this same behavior in this test case:
    http://live.datatables.net/nujosona/1/edit

    If you are using ajax then Datatables will overwrite the DOM based table. You could have a DOM based table and use jQuery ajax() to fetch the data followed by rows.add() to add the server based data to the DOM based table. However, doing this would remove the capability of using Datatables server side processing.

    Does this answer your questions?

    Kevin

  • SakullSakull Posts: 5Questions: 1Answers: 0

    I'm sad :(
    I need use server site processing.
    I have to change my approach to code - change a code.
    Thank you for help.

This discussion has been closed.