Datatables implementation with Zurb Foundation
Datatables implementation with Zurb Foundation
bikedorkseattle
Posts: 20Questions: 1Answers: 0
Looking to see if anyone has done an implementation of Datatables with Foundation. Found the Bootstrap one which was awesome.
This discussion has been closed.
Replies
If you do create an integration layer between the two, I've got a Github repo for this kind of integration, if you would be willing to share it with the world: https://github.com/DataTables/Plugins/tree/master/integration (Bootstrap is the only one thus far, but others can be added!).
Allan
Allan
http://www.zurb.com/playground/responsive-tables
http://foundation.zurb.com/docs/forms.php
It appears I need to override _fnFeatureHtmlLength, but I'm not sure how to go about that as I'm a jQuery novice.
To replace it entirely you need to create a feature plug-in, as described here: http://datatables.net/blog/Creating_feature_plug-ins
Allan
The Foundation form syntax looks like this.
[code]
"oLanguage": {
"sLengthMenu": 'Dropdown Label'+
''+
' 10'+
' 20'+
' 30'+
''+
''+
' This is a dropdown'+
' '+
' '+
' 10'+
' 20'+
' 30'+
' '+
''
[/code]
Currently I am able to get DT to change the menu length, but there is a catch. When you click on a length, say 20, it returns results for the previous length selection. Doh.
In _fnFeatureHtmlLength I'm replacing:
[code]
$('select', nLength).bind( 'change.DT', function(e) {
var iVal = $(this).val();
[/code]
with
[code]
$('div.custom ul', nLength).bind( 'click' , function(){
var iVal = $('div.custom ul li.selected', nLength).text();
[/code]
I know the problem is that when I click and select the length option the selected class has not been applied to the clicked on list item. I've tried doing this many different ways but I end up with the same result.
Since I can't detect a select change I wanted to detect a change of class with the list item, but you can't do that. The work around is in the Foundation js I add a trigger to the addClass/deleteClass portion of their code. It actually appears there is a change trigger already. However, what isn't clear to me is whether a trigger like .trigger('cssClassChange') in Foundation will work in DT. When you create an event with trigger are they global?
This is a blog post showing how feature plug-ins can be created: http://datatables.net/blog/Creating_feature_plug-ins
I suspect that this method will be a lot easier than shoehorning the built in method into doing something it wasn't really designed for :-)
Allan
I actually have everything working, just not as a plugin, and since this is my first time doing something like this I'm having some difficulty knowing how to proceed in creating a plugin that overrides the stock function. Could you provide me with a little bit more direction. Do I want to do something like this?
$.extend( $.fn.dataTableExt._fnFeatureHtmlLength = function( oSettings ) {}
Thanks
edit: I've uploaded some of the files to github, still a work in progress.
https://github.com/entropytc/Foundation-Datatables
Possibly, but I doubt it. I'm not entirely sure what you are trying to achieve there? Are you trying to overwrite the internal DataTales function? You can't do that I'm afraid - its a private method and can only be changed by actually changing the DataTables source code.
Allan
Just revisiting this, sounds like I need to look through some other people's plugins to figure out how to override that functionality.
Allan
$.fn.DataTable.prototype.constructor.ext.oApi._fnFeatureHtmlFilter = function () {}
Allan
Anything new on this side?
I would also be interrested in the integration between Zurb Foundation 3 and datatable. I could help testing and improving it.
Thanks.
Jerome
I would also love to know how bikedorkseattle got on with this. I'm happy to help test and improve it.
Cheers,
Ben
I have implemented a complete integration based on bikedorkseattle's codebase. Please find it at https://github.com/jhkchan/Foundation-Datatables and hope it helps.
Cheers,
Jacky