3

I'm using Datatables to represent data from a JSON. This is my JSON:

[{"postIMAGE": "/images/abc.jpg", "postTITLE": "Some Text", "postURL" : "blah", "postSection" : "blah"}]

This is my code:

var table = $('#tableId').DataTable({
        "ajax": {
            "url": "loadSiteContent",
            "dataSrc": "",
            data: {sectionUrl: "", siteUrl: siteurl}
        },
        "columns": [
            {"data": "postIMAGE", "render": function (data) {
                    alert(data);
                    return '<img src=' + data + ' width="154" height="115"/>';
                }},
            {"data": "postTITLE"},

            {"data": "postURL", "render": function (data) {
                    return '<a href=' + data + ' target="_blank" rel="nofollow"/>' + data + '</a>';
                }}
        ]
    });

So the view will be like this:

Enter image description here

But I want to create the table like following. How do I do that? Single column and all details in that single sell.

Enter image description here

1
  • Datatables is meant for tabular data. What you want is not tabular, so Datatables is not the right job for this. Commented Aug 25, 2016 at 5:01

1 Answer 1

2

You can use render for that:
For example:

{
    data: null,
    name: null,
    orderable: false,
    render: function (data, type, row) {
       return row.Field1 +
              "<img src='" + row.Field2 + "' />";           
    }
},

In other word, you create single column and show all data into it by using row.fieldName like top example.
I hope this be useful.

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

Comments

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.