filamentgroup / tablesaw

A group of plugins for responsive tables.
MIT License
5.48k stars 434 forks source link

toggle mode gives error in console on resize on pages without table #222

Closed fortm closed 7 years ago

fortm commented 8 years ago

Thanks for awsome plugin

I am facing an issue. The tablesaw plugin is activated on an ajax page that contains table with toggle enabled. Everything works fine on that page until switching to another page by second ajax request where there is no tablesaw table.

init code -

$("#grid table").attr("data-tablesaw-mode","columntoggle");
 $("#grid table").attr("data-tablesaw-minimap","");
 $("#grid table").attr("data-tablesaw-sortable","");
 $("#grid table").attr("data-tablesaw-mode-exclude","columntoggle");                                
 $("#grid table").attr("data-tablesaw-mode-switch","");                                                         
 $(document).trigger( "enhance.tablesaw" );

CSS class for table - tablesaw tablesaw-columntoggle

Also data-tablesaw-priority is provided for each column between value 1 to 6

resizing console in chrome gives following error in second tab without table: seems like javascript binding is causing some issue

tablesaw.js:470 Uncaught TypeError: Cannot read property 'eq' of undefined

(anonymous function)    @   tablesaw.js:470
jQuery.extend.each  @   jquery.js:611
jQuery.fn.jQuery.each   @   jquery.js:241
ColumnToggle.refreshToggle  @   tablesaw.js:467
(anonymous function)    @   tablesaw.js:460
jQuery.event.dispatch   @   jquery.js:3058
elemData.handle.eventHandle @   jquery.js:2676

This error happens only with Toggle option and on pages where there is no table on resize.

How can we fix this ?

fortm commented 8 years ago

Only when I am running as below on second ajax request without table , errors go away related to refreshToggle -

$(window ).unbind( "resize.table-987" );

Is there any wrong configuration in my setup ?

zachleat commented 8 years ago

Try out 3.0 and let me know if this doesn’t work for you!

fortm commented 8 years ago

I replaced 2.0.1 tablesaw.js with latest v3.0.0-beta.0 tablesaw.jquery.js and same with css I am using jquery 1.8.3

On resizing console on pages without table , I get now below error -> tablesaw.js:521 Uncaught TypeError: Cannot read property 'cells' of undefined

fortm commented 8 years ago

I am current intercepting all Ajax requests and doing as below - Since without this even new version gives error

XMLHttpRequest.prototype.send = function(data) {
            $(window).OffRegexNameSpaces("resize",/^table-\d{3}/);        
                send.call(this, data);       
 };
})(XMLHttpRequest.prototype.send);

For regex function, using below link -

[http://stackoverflow.com/questions/38806912/unbind-to-multiple-namespaced-events-in-jquery]

zachleat commented 8 years ago

I think I’m going to need a test case to fix this properly. I don’t quite understand what you’re doing. Can you put a reduced test case that shows the problem on jsbin (or similar)? If you do this soon, it’ll probably make it into 3.0. Thank you!

zachleat commented 7 years ago

Please reopen with a test case!