jquery - Change TableSorter sorting criteria -


i'm trying use jquery tablesorter plugin, sort table of books create querying mysql database php.

the table sorted title mysql engine (order book.title in query) , user free sort table in different manner via tablesorter (number of pages, author name, publication date, &c.).

the thing is, books have names start numbers (such "1984" or "20.000 leagues under sea"). mysql puts these books on top, before other books start letter. have no quarrel this, strange "bug" (not bug maybe) emerges tablesorter: sorts number-starting titles (shifting them beggining of table end), leaving rest (and vast majority) of items order unchanged. think i've tracked down origin of problem, couldn't yet find (true) solution:

it seems tablesorter looks @ first row determine type of column , deems numerical 1 because first element book title starts number, ignores cell starts alphabetic character. if reverse order of original sorting (changing mysql query ending order book.title desc), first element book starting letter (z or nearest one), tablesorter thinks it's alphanumerical column , sorts fine, table presented in unusual , awkward ordering user.

for have same problem (i don't think i'm first 1 run this, couldn't find posts relating "bug", nor way fix it), managed devise quick fix: putting hidden row first forces each column sorting criteria right one, this:

  <tr>       <td class = "row-hidden">abc</td> <!-- title -->       <td class = "row-hidden">abc</td> <!-- subtitle -->       <td class = "row-hidden">abc</td> <!-- author -->       <td class = "row-hidden">123</td> <!-- pages -->       <td class = "row-hidden">123</td> <!-- quotes -->       <td class = "row-hidden">01/01/1970</td> <!-- publication date -->       <td class = "row-hidden"></td> <!-- no sorting required -->   </tr> 

but bypass , i'd know if there's way solve actual problem, question this: there way force/set sorting criteria of given column (via jquery) manually overriding parser decides automatically??

tablesorter attempts determine type of data contained in column starting first row , scanning down until 1 of parsers hits match. shouldn't, when sees "20.000 leagues..." thinks it's looking @ numeric data, parser gets set "digit".

to override behavior, set headers option column. once set, column data no longer auto-detected.

$('table').tablesorter({   headers : {     // using zero-based column index     0 : { sorter: 'text' }   } }); 

in case you're interested, have fork of tablesorter includes, still needs loaded, ignore leading articles parser sorts titles ignoring leading articles "a", "an" , "the". other languages supported.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -