Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot read property 'replace' of undefined #1151

Closed
ashish-bhanderi opened this issue Feb 3, 2016 · 8 comments
Closed

cannot read property 'replace' of undefined #1151

ashish-bhanderi opened this issue Feb 3, 2016 · 8 comments

Comments

@ashish-bhanderi
Copy link

When I applied sorting on first column which contains text,

At that time it gives an error "cannot read property 'replace' of undefined" in function sortNatural
Line no: 1760
aNum = a.replace( regex.chunk, '\0$1\0' ).replace( regex.chunks, '' ).split( '\0' );

because variable a is undefined.

Can you please put condition over-there?

@Mottie
Copy link
Owner

Mottie commented Feb 3, 2016

Hi @ashish-bhanderi!

The natural sort function only accepts strings. There is a note at the start of the function:

// Natural sort - https://github.com/overset/javascript-natural-sort (date sorting removed)
// this function will only accept strings, or you'll see 'TypeError: undefined is not a function'
// I could add a = a.toString(); b = b.toString(); but it'll slow down the sort overall

If you're seeing an error, then the first column in your table must be parsing values... please make sure that a "text" parser is being used.

@ashish-bhanderi
Copy link
Author

I am applying sorting on text fields only.
The case is below.
In my table suppose I have three values ("BBB", "ddd", "eee");

So, For the first iteration it should compare "BBB" and "ddd". Instead of that it is doing below thing.
First iteration value of variable a is undefined while value of variable b is "BBB".
in next iteration value of variable a will be "BBB", while value of variable b will be "ddd".

That's why I am asking to put below condition
if(a != undefined)
aNum = a.replace( regex.chunk, '\0$1\0' ).replace( regex.chunks, '' ).split( '\0' );

@Mottie
Copy link
Owner

Mottie commented Feb 4, 2016

Would you please modify this demo so that it duplicates this error.

Sorry, I am being stubborn, because the natural sort function is used a lot while sorting and any extra code means it slows down that much more... it may not be noticeable in small tables in Chrome, but try a large table in Internet Explorer.

Once I have time to integrate clusterize into the code, it may not be much of an issue anymore.

@Mottie
Copy link
Owner

Mottie commented Mar 2, 2016

Any update on this issue?

@ashish-bhanderi
Copy link
Author

I found other solution.
Code was fine.
Thanks

@roctoll
Copy link

roctoll commented Jul 8, 2016

Hey @ashish-bhanderi! what solution did you find? I have the same problem for empty rows..

@Mottie
Copy link
Owner

Mottie commented Jul 8, 2016

Hi @roctoll

I'm not sure why you're getting an undefined error, but ok ok I give in... I'll add a fix to fallback to an empty string, but I still don't think I need to add a .toString().

@melisekp
Copy link

melisekp commented Jun 5, 2018

Had the same problem.
Found out that instead of closing my table row tag i opened another and while most browsers take this correctly. Tablesorter seems to add an empty row and so it find that undefined value.
Well double-check your html :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants