vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
731 stars 285 forks source link

Fixed issue of improper undefined check against settingsDt.aanFeatures.f #597

Closed mpdas108 closed 4 years ago

mpdas108 commented 4 years ago

Discovered this issue when trying to reset filters on a server side implementation.

vedmack commented 4 years ago

thx, but please add this fix only in src folder

mpdas108 commented 4 years ago

I have added to only the src folder now.

vedmack commented 4 years ago

@mpdas108 b.t.w, what issue exactly does the previous undefined check introduced?

mpdas108 commented 4 years ago

This problem is only applicable to those using server side filtering, and trying to reset all the filters using yadcf.exResetAllFilters() function. Resetting the filters one by one, works as intended.

settingsDt.aanFeatures.f is not properly seen as undefined so the conditional statement returns true when it should return false. This causes the script to wrongly enter the conditional block and the script produces an error visible in the console when trying to execute the next line which tries to check the length of settingsDt.aanFeatures.f :

for (i = 0; i < settingsDt.aanFeatures.f.length; i++) { ,

The error is thrown then because settingsDt.aanFeatures.f is actually undefined. The result of this error is that the filters are physically reset, but the server is not queried again for results, leaving an empty table.

vedmack commented 4 years ago

but typeof should be checked against 'undefined' (wrapped with an apostrophe) ?

mpdas108 commented 4 years ago

My mistake, in my live version I do have quotes. I forgot them in my local version that I used to submit the PR.

mpdas108 commented 4 years ago

I also understand that variable === undefined, and variable !== undefined should work. but for some reason I kept getting undefined errors, meaning the if (settingsDt.aanFeatures.f !== undefined) { was failing to detect undefined.

mpdas108 commented 4 years ago

I added the quotes.

vedmack commented 4 years ago

Thanks for the fix, I guess it happened because in your scenario f was not declared in settingsDt.aanFeatures.f