Is there any Ruby gem for the DataTables ?
Is there any Ruby gem for the DataTables ?
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
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
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
This screencast might be useful for implementing server-side processing.
Allan
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 :
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
This is the key one if you want to implement server-side processing.
Allan
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 :
Any kind of help will be helpful for me.
Thanks,
Shekhar
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%" }
],
I didn't understand where to put my data array in this above script. Can you help me in this ?
--
Shekhar
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.
Thanks bindrid. I want to pass data array something like this example :https://datatables.net/extensions/scroller/examples/initialisation/large_js_source.html
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
I missed one key thing in my example.
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.
Thanks bindrid !
Can we load data from the javascript array (data array) into Ajax function ?
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.
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.htmlCan we do something like this ?
--
Shekhar
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