0

I am planning to use JQuery Datatables in one of my project, so i decided to do a POC to ensure that everything is planned.

I build a table where i will be printing the values from my Object which will be received as a JSON during my further development. But i am getting an AJAX error for the id i was going to print the data.

I have uploaded the code on JSFiddle!

HTML

 <div id="tab-customers">
            <table id="customers-table" class="display general-table" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Email</th>
                        <th>Phone</th>
                        <th>Gender</th>
                        <th>City</th>
                        <th>Country</th>
                    </tr>
                </thead>
            </table>
        </div>

JQuery

 $(".tabs").click(function() {
                var source = $(this).data("source");
                var tableId = $(this).data("table");
                initiateTable(tableId, source);
            });
function initiateTable(tableId, source) {
                var table = $("#" + tableId).DataTable({
                    "ajax": source,
                    order: [],
                    columnDefs: [{
                        orderable: false,
                        targets: [0]
                    }],
                    "destroy": true,
                    "bFilter": true,
                    "bLengthChange": false,
                    "bPaginate": false
                });
            }
            initiateTable("customers-table", "customers");
            $("#dynamic-tabs").tabs();
        });

1 Answer 1

1

Try the columns option

columns: [
    { "data": "Id" }, 
    { "data": "firstName" }, 
    { "data": "lastName" }, 
    { "data": "email" }, 
    { "data": "phone" }, 
    { "data": "gender" }, 
    { "data": "city" }, 
    { "data": "country" }
]

Demo

Sign up to request clarification or add additional context in comments.

2 Comments

Does that mean the column would need separate data object ?
use seprate variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.