Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82668

Adding an empty row (at the left) ...

$
0
0

Hi All,

I hope smb can help ... Struggling with this for a couple of hrs now ...

I'm trying to add an empty column to the left of a datatable ... (later on ... an "edit" button will be placed in this column... )

Everything works fine, as long as I'm putting "data" in the left-most column. As soon as I'm replacing the data-col (in this case... "ID" ... with data:null and defaultContent:'' ... I get an AJAX error (see also JS source code...

Thanks in advance for your help !!!!

Regards,

Johnny Belgium

My HTML Source ...

<html>
<head>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<title>Rooms</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">


<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css">
  
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>





<!-- DataTables JS -->

<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>

</head>
<body>
<div class="wrapper">
    <table id="example" class="display compact" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Action</th>
                <th>ID</th>
                <th>Name</th>
                <th>Description</th>
            </tr>
        </thead>
        
    </table>
</div>
</body>
</html> 

My JS Code:

<script type="text/javascript">


    $('#example').DataTable( {
    serverSide: true,
    processing: true,
    start : 0,
    length : 5,
    PaginationType: 'full_numbers',
    lengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, 'All']],
    
     columnDefs: [ 
            {
            "targets": 0,
            "data": "id",
            // My problem occurs when 
            // commenting the "data": = "id" line and uncommenting the 2 lines below, 
            // results in an AJAX error 
            
            // "data": null,
            // "defaultContent": '',
            },
            {
            "targets": 1,
            "data": "id"
            },
            
            {
            "targets": 2,
            "data": "name"
            },
            {
            "targets": 3,
            "data": "description"
            }           
        ],
    
    ajax: {
        url: 'http://localhost:8081/bs/rooms/datatable',
        type: 'POST'
    },
    
} );
</script>

In case it would help ... this is my JSON data:

{"draw":0,"recordsTotal":6,"recordsFiltered":6,"data":[{"id":"1","name":"Room 01","description":"Descr 01"},{"id":"2","name":"Room 02","description":"Descr 02"},{"id":"3","name":"Room 03","description":"Descr 03"},{"id":"4","name":"Room 04","description":"Desc 04"},{"id":"5","name":"Room 05","description":"Descr 05"},{"id":"6","name":"Room 06","description":"Descr 06"}]}

Thanks !!


Viewing all articles
Browse latest Browse all 82668

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>