how to generate dynamic datatable by using jstl and ajax?

how to generate dynamic datatable by using jstl and ajax?

karamkaram Posts: 31Questions: 14Answers: 0
edited October 2015 in Free community support

I am using data tables 1.10.9 and i want to create dynamic table by using jstl and i am also using ajax to load the data. my question is how to fit the jstl code in datatables. i have more than 50 columns.

*jstl code**:

name city

</html>

$(document).ready( function () {

 var table;

 table= $('#example).DataTable( {



            "processing": true,

            "deferRender": true,

            //"searching": true,

            //"serverSide": true,                   

             dom: 'BRlfrtip',

             buttons: [

                        {  extend: 'colvis',

                            text: 'Change Layout',

                            collectionLayout: 'fixed three-column'

                        }                     

                     ],             



             "ajax": {

                        "url": "/example.so",

                        "type": "GET"

                         },

"columns": [{

        "title": "name",

        "data": "name",

        "name": "name"

    }, {

        "title": "city",

        "data": "city",

        "name": "city"

    }]

});
     var noofcolumn= $('#example thead th').length;
                                    colmn="";

                                    for(i=0; i<noofcolumn; i++)
                                    {
                                    var title = $('#example thead th').eq( i ).text();
                                    colmn+='<th><input type="text" placeholder="Search" /></th>';
                                    }
                                    $('#example tfoot').html( colmn );

                                 // Apply the search

                                    table.columns().every( function ()
                                            {
                                    $('input', this.footer() ).on( 'keyup change', function () {
                                        table
                                            .column( $(this).parent().index()+':visible' )
                                            .search( this.value )
                                            .draw();

                                    } );                
                        });  

Answers

  • karamkaram Posts: 31Questions: 14Answers: 0

    jstl code <c:forEach items="${tblRslt}" var="put">
    <tr>
    <td>${put.name}</td>
    <td>${put.city}</td>

    </tr>
    

    </c:forEach>

This discussion has been closed.