DataTables & SharePoint

DataTables & SharePoint

cchin25cchin25 Posts: 1Questions: 0Answers: 0
edited July 2012 in DataTables 1.9
Does anyone have an example of using DataTables with SharePoint 2010? I'm attempting to pull list data as json using the built in web services. Unfortunately I'm running on an internal environment so I can't link to an example of what I'm trying to do. I got it up to the point where i can tell DataTables is rendering, but it does not display any results.




Here is the call I'm making
[code]
$(document).ready(function () {
$.ajax({
url: "url to my web service",
type: 'GET',
dataType: 'JSON',
cache: false,
success: function (json) {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": json,
"aoColumns": [
{ "asSorting": [ "asc" ] }
]
});

},
error: function () {
alert("Error");
}
});
});
[/code]

Thanks for any assistance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Let DataTables make the JSON call for you just use:

    [code]
    $('#example').dataTable({
    "bProcessing": true,
    "sAjaxSource": "url to my web service",
    "aoColumns": [
    { "asSorting": [ "asc" ] }
    ]
    });
    [/code]

    The alternative is to pass the data in using aaData (not sAjaxSource):

    [code]
    $(document).ready(function () {
    $.ajax({
    url: "url to my web service",
    type: 'GET',
    dataType: 'JSON',
    cache: false,
    success: function (json) {
    $('#example').dataTable({
    "bProcessing": true,
    "aaData": json,
    "aoColumns": [
    { "asSorting": [ "asc" ] }
    ]
    });

    },
    error: function () {
    alert("Error");
    }
    });
    });
    [/code]

    Allan
This discussion has been closed.