Tablesorter - Custom Sorts
|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Tablesorter - Custom Sorts[Tried posting this, but never saw it go through. Sorry if it duplicates] I am having a couple issues with how to sort a few of my fields. The first, and I think most difficult is I have a field which holds the value of "Empty" or lists state abbreviations. What I'd like it to do is have "Empty" be grouped together and then sort the state abbreviations in alpha. I tried the grades demo, but with no success. The second is I have an ID field which is constructed by the year and then a sequential number. Example - 2008 - 1, 2008 - 2, 2008 - 3, etc. The problem is that when sorted it sorts like this... 2008 - 90, 2008 - 9, 2008 - 89 It does see the 9 as coming after 8 and before 10, but between 90 and 89. Help with either one is greatly appreciated. Seth |
|
|
Re: Tablesorter - Custom SortsI've been working with the Tablesorter plugin recently and had to do something similar. You can make your own textExtraction function and use it to extract an organize the data how you want. In your case I'd probably do something where you parse out just the numbers, zero pad them, concat together and return a parseInt on it. The biggest problem I had was youc an only specify 1 textExtraction function to use so I added an attribute to the table cells to specify the kind of data then my textExtraction function decided what to do based on that. Example: $.tablesorter.defaults.textExtraction = function (node) { var r, v; try { v = node.attr("textExtraction"); } catch(e) { v = "none"; } switch (v) { case "specialdate": //do your stuff and set it to v break; default: v = node.innerHTML; break; } return v; }; On May 13, 1:16 pm, Seth - TA <seth.mcguinn...@...> wrote: > [Tried posting this, but never saw it go through. Sorry if it > duplicates] > > I am having a couple issues with how to sort a few of my fields. > > The first, and I think most difficult is I have a field which holds > the value of "Empty" or lists state abbreviations. What I'd like it to > do is have "Empty" be grouped together and then sort the state > abbreviations in alpha. I tried the grades demo, but with no success. > > The second is I have an ID field which is constructed by the year and > then a sequential number. > Example - 2008 - 1, 2008 - 2, 2008 - 3, etc. > The problem is that when sorted it sorts like this... > 2008 - 90, 2008 - 9, 2008 - 89 > > It does see the 9 as coming after 8 and before 10, but between 90 and > 89. Help with either one is greatly appreciated. > > Seth |
|
|
Re: Tablesorter - Custom SortsI can't get your example to work.
When I try to debug by adding this line: var r, v; console.log(node.attr("textExtraction"));
try { v = node.attr("textExtraction"); } I get the error "node.attr is not a function". /Daniel
On Tue, May 13, 2008 at 11:09 PM, Scott <polypill@...> wrote:
|
|
|
Re: Tablesorter - Custom Sorts(I hope I didn't double post this) I can't get your example to work. When I try to debug by adding this line: var r, v; console.log(node.attr("textExtraction")); try { v = node.attr("textExtraction"); } I get the error "node.attr is not a function". On May 13, 11:09 pm, Scott <polyp...@...> wrote: > I've been working with the Tablesorter plugin recently and had to do > something similar. You can make your own textExtraction function and > use it to extract an organize the data how you want. In your case I'd > probably do something where you parse out just the numbers, zero pad > them, concat together and return a parseInt on it. The biggest problem > I had was youc an only specify 1 textExtraction function to use so I > added an attribute to the table cells to specify the kind of data then > my textExtraction function decided what to do based on that. > > Example: > $.tablesorter.defaults.textExtraction = function (node) > { > var r, v; > try { v = node.attr("textExtraction"); } > catch(e) { v = "none"; } > switch (v) > { > case "specialdate": > //do your stuff and set it to v > break; > default: > v = node.innerHTML; > break; > } > return v; > > }; > > On May 13, 1:16 pm, Seth - TA <seth.mcguinn...@...> wrote: > > > [Tried posting this, but never saw it go through. Sorry if it > > duplicates] > > > I am having a couple issues with how to sort a few of my fields. > > > The first, and I think most difficult is I have a field which holds > > the value of "Empty" or lists state abbreviations. What I'd like it to > > do is have "Empty" be grouped together and then sort the state > > abbreviations in alpha. I tried the grades demo, but with no success. > > > The second is I have an ID field which is constructed by the year and > > then a sequential number. > > Example - 2008 - 1, 2008 - 2, 2008 - 3, etc. > > The problem is that when sorted itsortslike this... > > 2008 - 90, 2008 - 9, 2008 - 89 > > > It does see the 9 as coming after 8 and before 10, but between 90 and > > 89. Help with either one is greatly appreciated. > > > Seth |
|
|
Re: Tablesorter - Custom SortsYeah, sorry, forgot I was switching between jquery and non-jquery syntax. I'll make it all jquery so it is consistent. $.tablesorter.defaults.textExtraction = function (node) { var r, v; try { v = $(node).attr("textExtraction"); } catch(e) { v = "none"; } switch (v) { case "specialdate": //do your stuff and set it to v break; default: v = $(node).html(); break; } return v; }; On May 14, 7:37 am, Daniel Eriksson <diinodan...@...> wrote: > (I hope I didn't double post this) > > I can't get your example to work. > > When I try to debug by adding this line: > > var r, v; > console.log(node.attr("textExtraction")); > try { v = node.attr("textExtraction"); } > > I get the error "node.attr is not a function". > > On May 13, 11:09 pm, Scott <polyp...@...> wrote: > > > I've been working with the Tablesorter plugin recently and had to do > > something similar. You can make your own textExtraction function and > > use it to extract an organize the data how you want. In your case I'd > > probably do something where you parse out just the numbers, zero pad > > them, concat together and return a parseInt on it. The biggest problem > > I had was youc an only specify 1 textExtraction function to use so I > > added an attribute to the table cells to specify the kind of data then > > my textExtraction function decided what to do based on that. > > > Example: > > $.tablesorter.defaults.textExtraction = function (node) > > { > > var r, v; > > try { v = node.attr("textExtraction"); } > > catch(e) { v = "none"; } > > switch (v) > > { > > case "specialdate": > > //do your stuff and set it to v > > break; > > default: > > v = node.innerHTML; > > break; > > } > > return v; > > > }; > > > On May 13, 1:16 pm, Seth - TA <seth.mcguinn...@...> wrote: > > > > [Tried posting this, but never saw it go through. Sorry if it > > > duplicates] > > > > I am having a couple issues with how to sort a few of my fields. > > > > The first, and I think most difficult is I have a field which holds > > > the value of "Empty" or lists state abbreviations. What I'd like it to > > > do is have "Empty" be grouped together and then sort the state > > > abbreviations in alpha. I tried the grades demo, but with no success. > > > > The second is I have an ID field which is constructed by the year and > > > then a sequential number. > > > Example - 2008 - 1, 2008 - 2, 2008 - 3, etc. > > > The problem is that when sorted itsortslike this... > > > 2008 - 90, 2008 - 9, 2008 - 89 > > > > It does see the 9 as coming after 8 and before 10, but between 90 and > > > 89. Help with either one is greatly appreciated. > > > > Seth |
|
|
Re: Tablesorter - Custom SortsI'm pretty sure the recommended way to achieve this is to use the "addParser" functionality. Then you can specify which fields should use your custom parser using either metadata or options. Overriding the textExtraction seems like using a sledgehammer to me rather than a precision tool. On May 13, 1:16 pm, Seth - TA <seth.mcguinn...@...> wrote: > [Tried posting this, but never saw it go through. Sorry if it > duplicates] > > I am having a couple issues with how to sort a few of my fields. > > The first, and I think most difficult is I have a field which holds > the value of "Empty" or lists state abbreviations. What I'd like it to > do is have "Empty" be grouped together and then sort the state > abbreviations in alpha. I tried the grades demo, but with no success. > > The second is I have an ID field which is constructed by the year and > then a sequential number. > Example - 2008 - 1, 2008 - 2, 2008 - 3, etc. > The problem is that when sorted it sorts like this... > 2008 - 90, 2008 - 9, 2008 - 89 > > It does see the 9 as coming after 8 and before 10, but between 90 and > 89. Help with either one is greatly appreciated. > > Seth |
|
|
Re: Tablesorter - Custom SortsYeah, probably for his case you're right, but the parser is given the innerHTML of the node and if you've got other html elements in the node you end up with a rather messy string to parse. If the parser was just passed the node itself or be able to set a flag for what form you want your argument to be I think it would be better. On May 14, 11:13 am, tlphipps <tra...@...> wrote: > I'm pretty sure the recommended way to achieve this is to use the > "addParser" functionality. Then you can specify which fields should > use your custom parser using either metadata or options. > Overriding the textExtraction seems like using a sledgehammer to me > rather than a precision tool. > > On May 13, 1:16 pm, Seth - TA <seth.mcguinn...@...> wrote: > > > [Tried posting this, but never saw it go through. Sorry if it > > duplicates] > > > I am having a couple issues with how to sort a few of my fields. > > > The first, and I think most difficult is I have a field which holds > > the value of "Empty" or lists state abbreviations. What I'd like it to > > do is have "Empty" be grouped together and then sort the state > > abbreviations in alpha. I tried the grades demo, but with no success. > > > The second is I have an ID field which is constructed by the year and > > then a sequential number. > > Example - 2008 - 1, 2008 - 2, 2008 - 3, etc. > > The problem is that when sorted it sorts like this... > > 2008 - 90, 2008 - 9, 2008 - 89 > > > It does see the 9 as coming after 8 and before 10, but between 90 and > > 89. Help with either one is greatly appreciated. > > > Seth |
| Free Forum Powered by Nabble | Forum Help |