1

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.

1 Answer 1

2

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!!

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

4 Comments

Thanks, this is helpful. Do you also have server side (Rails) example?
Server side (Rails) example? I didnt get you..for datatable?
Rails server side example to provide the JSON/ajax results needed that Datatable can consume.
Yes, I can give example $.ajax({ url: '/example/search_result', method: 'post', dataType: 'JSON', async: false, data:data_params, success: function (data){ table.fnDraw(); }, failure: function (msg) { console.log("Error in sending data"); } });

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.