Is there any Ruby gem for the DataTables ?

Is there any Ruby gem for the DataTables ?

shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0
edited July 2017 in Free community support

I want to use DataTables in IRuby notebook as well as for ruby web application. So if there is a good gem that uses the DataTables JS as the backend and generated the html and javascript for the table, will be very useful for me.

I want to use DataTables for importing large data set. I have read articles for this. I like few articles on scrollY : https://datatables.net/extensions/scroller/examples/initialisation/large_js_source.html and https://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html . Which loads the data from the server piece by piece and fast.

I want Ruby gem so that I can use it in daru-view gem : https://github.com/shekharrajak/daru-view , for getting large data_set smoothly and use some features of DataTables.

Any kind of help will be appreciated.

Thanks,
Shekhar

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    DataTables is a client-side library, so I'm not planning on releasing any server-side Ruby code for it. If you need the server-side aspect as well, that is something you would need to look for on rubygems.org or similar.

    Allan

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    One thing I need is loading data in pieces from the present file (csv or other file type) in my system to web application. The file size is very large so I want to load it in pieces . Like I am scrolling and more data is going to load accordingly .

    Some explanation : Using daru gem we load data and create DataFrame. Daru DataFrame I can generate html table for the web page. So using it I can save very large data set into html table code. Now I want to load this html code (millions of lines) into webpage, which can make my app slow. So I want to use DataTables and load only 200 line (one scroll) then user is scrolling and more data is loaded and displayed. Like this :https://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html

    If you have any suggestion then let me know.

    Thanks,

    Shekhar

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    This screencast might be useful for implementing server-side processing.

    Allan

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    Thanks for sharing the link. It took me time to understand it. It is rails specific but I want it to work for all the ruby web application framework like Rails, Sintara, Nanoc. May be I can create gem that will use be able to generate javascript and html code for the Daru dataframe table.

    I am focused on these articles :

    1. https://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html
    2. https://datatables.net/extensions/scroller/examples/initialisation/large_js_source.html

    So I want to use scrollY, scroller or just pagination (current page will be loaded. When user click on next then next page data must be fetched ).

    --
    Shekhar

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    This is the key one if you want to implement server-side processing.

    Allan

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    Thanks! I have tried few lines that I want to use in my gem to load the large data set. The github repo of the example is here : https://github.com/Shekharrajak/datatables-sample-daru

    Live demo : https://shekharrajak.github.io/datatables-sample-daru/

    When you run this links : https://shekharrajak.github.io/datatables-sample-daru/server_side/static.html , it will just load the entire data into browser so it takes too much time and your browser crashes.

    Same amount of data is loading in this link: https://shekharrajak.github.io/datatables-sample-daru/server_side/server.html and it is pretty fast to load and shows in data according to the scrolling.

    In both the link I am loading 16042100 number of rows.

    Can I know the limit of the number of rows DataTable can handle? Is it 5,000,000 rows?

    I personally feeling some problem in understanding these options meaning :

    processing, data.draw, recordsTotal, recordsFiltered, deferRender, scrollCollapse.

    I also want to use pagination with server side processing. I read related articles one of them is : https://datatables.net/forums/discussion/32031/pagination-with-server-side-processing

    But it is not working for me. Right now I have added these lines which is not working :

                pagingType: "full_numbers",
                pageLength: 10,
                paging: true,
    
    

    Any kind of help will be helpful for me.

    Thanks,
    Shekhar

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    I want to load the Ruby array of data into javascript and then that Array of data will be used in the DataTable script.

    I have these lines right now :

    $(document).ready( function () {
    var table = $('#example').DataTable({
    deferLoading: 0,
    retrieve: true,
    processing: true,
    serverSide: true,
    searching: false,
    autoWidth: false,
    dom: "rt<'row'<'col-xs-3'l><'col-xs-9'p>><'row'<'col-xs-12 text-center'i>>",
    lengthMenu: [5, 10, 25],
    pagingType: "simple_numbers",
    sort: false,
    ajax: {
    data: function(data) {
    var page = (data.start / data.length) + 1;
    console.log(data)
    data.page = page;
    data.per_page = data.length;
    }
    },
    sAjaxDataProp: '',
    columns: [
    { data: "id", title: "id", width: "3%" },
    { data: "name", title: "name", width: "30%" }
    ],

          });
    
          table.page('next').draw('page');
    
        } );
    

    I didn't understand where to put my data array in this above script. Can you help me in this ?

    --
    Shekhar

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    edited July 2017

    Because you have not return on your function you are actually sending no parameters to your server. Also key in mind that "data" is what is being sent to the server, not what is coming back. (yes, I know it is not intuitive, blame jquery). Below, I changed your code to see what is going on with ajax. I changed the data parameter variable name to be more fitting to what it is.

        ajax: {
            data: function(parameters) {
                var page = (parameters.start / parameters.length) + 1;
                parameters.page = page;
                parameters.per_page = parameters.length;
                return parameters;
            },
            // this function lets you see the data exactly as it is sent from the server.
            // most likely in a serialized string.  I have used this feature in the past
            // to but the data in the form that datatables expect  when I have no control
            // over the format the server sends out.
            dataFilter: function(res){
                console.log(res);
                return res;
            },
            error: function(err){
                //lets you see the details of any errors.
                // if you use this, keep in mind that you are over writing 
                // DataTables error handler
                debugger;
                console.log(err);
    
            }
        },
    
  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    Thanks bindrid. I want to pass data array something like this example :https://datatables.net/extensions/scroller/examples/initialisation/large_js_source.html

        var data = [];
        for ( var i=0 ; i<50000 ; i++ ) {
            data.push( [ i, i, i, i, i ] );
        }
    

    instead of this array I will put my data rows and want to pass it in the ajax function. The array can be very large so I want to load piece of data.

    --
    Shekhar

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    edited July 2017

    I missed one key thing in my example.

    ajax: {
    
       // if you are using ajax inside the datatabe, you have to include the url
        url:"you web server",
    
        data: function(parameters) {
            var page = (parameters.start / parameters.length) + 1;
            parameters.page = page;
            parameters.per_page = parameters.length;
            return parameters;
        },
        // this function lets you see the data exactly as it is sent from the server.
        // most likely in a serialized string.  I have used this feature in the past
        // to but the data in the form that datatables expect  when I have no control
        // over the format the server sends out.
        dataFilter: function(res){
            console.log(res);
            return res;
        },
        error: function(err){
            //lets you see the details of any errors.
            // if you use this, keep in mind that you are over writing 
            // DataTables error handler
            debugger;
            console.log(err);
     
        }
    },
    

    Note that it is also important to return the data in a format that datatable is expecting.

    This page describes in detail what datatable is going to send in the request ( as you have seen in the ajax.data section above) and what is you should be sending back from the server. https://datatables.net/manual/server-side

    If you do the ajax right DataTable will take care of displaying the data. Keep in mind that this data is not cached. If you go forward a page, backward a page, or anything else that impacts what is being displayed, another ajax call will be triggered.

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    Thanks bindrid !

    Can we load data from the javascript array (data array) into Ajax function ?

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    You can but you don't need to. If you have it in an array before you create your table it would be

    $(your table).DataTable({data:[your data array}])

    Note that this data is not the same data shown in the above ajax section.

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    Thanks ! I had already tried it with minor mistake. Now I can see it working. I have tried these examples :

    I understood this example :

    But I want to handle large data set so I want to use processing and serverSide.
    In this example I tried it :

    I know that data1.draw will not work. But I don't know what is other way. I want to do something similar to this example : https://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html

    Can we do something like this ?

    --
    Shekhar

  • shekharrajakshekharrajak Posts: 9Questions: 1Answers: 0

    I see the download link here : https://datatables.net/download/

    I have downloaded the DataTables dependent css and js files and using it in this gem : https://github.com/Shekharrajak/datatables.rb

    But I know it will be updated. So I want to update it automatically (using rake task). I just want to know if there is any link present that contains the latest release.

    For example , in this link : https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js

    we are able to download the dataTables.min.js current latest version (1.10.15, which is in the link) . I want link something like https://cdn.datatables.net/latest/js/jquery.dataTables.min.js which will download the latest release.

    Please share link if it is present.

    Thanks!

    -
    Shekhar

This discussion has been closed.