netwire
netwire

Reputation: 7225

jQuery DataTables v1.10 + Rails ajax data

RailsCasts episode 340 on DataTables was interesting, but with the release of DataTables v1.10, lots have changed. Ajax is simpler but API's are easier to configure. Does anyone have examples of Rails code that creates Ajax data for DataTables? It'll be useful if it can be used for sorting, searching, in addition to pagination.

Upvotes: 1

Views: 671

Answers (1)

Anuj Dubey
Anuj Dubey

Reputation: 347

Yes, it is very useful for sorting ,searching and also pagination both for client side as well as serverside but not at the same time. It is a very good plugin(gem), I have used it. Example:-Ajax data for datatable

var table = $("#example_id").DataTable({

    iDisplayLength: 100,
    bInfo: false,
    bSort: true,
    sPaginationType: "full_numbers",
    bStateSave: true,
    bDestroy: true,
    bProcessing: true,
    bServerSide: true,
    bFilter: false,
    sAjaxSource: '/example/action_name',
    fnServerParams: function (aoData) {
        aoData.push(
            { "name": "example1", "value": $("#_example1").val() },
            { "name": "example2", "value": 5 },
            { "name": "example3", "value": "My Name" }
        );
    },
    oLanguage:{
        sZeroRecords: "No records found."},
    "sDom": 'rtlfip'

});

Hope this will help you!!

Upvotes: 2

Related Questions