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

Table sorter storage #389

Closed
Francks11 opened this Issue Oct 15, 2013 · 11 comments

Comments

Projects
None yet
3 participants
@Francks11

Francks11 commented Oct 15, 2013

Hello,

I use the function "saveSort" of tableSorter and I have encounter a bug/a lack.

The same tablesorter is accessible by two differents url, but it is the same page and the same table.

I see in the source code that the save of sorting depends on the url... :

$.tablesorter.storage = function(table, key, val){
var d, k, ls = false, v = {},
id = table.id || $('.tablesorter').index( $(table) ),
url = window.location.pathname;

Is it possible to ensure that it does depend only on the table id?

Thank you

@Mottie

This comment has been minimized.

Show comment
Hide comment
@Mottie

Mottie Oct 15, 2013

Owner

Hi @Francks11!

I don't think that's a good idea. There are a lot of sites out there that use templates, ajax and/or the developer is just in the habit of naming all of the tables with the same ID - it's a different page, so why not?

As the storage code works now, it tries to make sure each table is unique by saving it's url, id and/or index on the page. If I only look for an ID, then every saved parameter, not just "saveSort" will be loaded for different tables.

So while I won't make this change, I can tell you that all you need to do is modify your own copy by setting the url to some constant, any constant... just modify this line:

url = 3; // window.location.pathname;
Owner

Mottie commented Oct 15, 2013

Hi @Francks11!

I don't think that's a good idea. There are a lot of sites out there that use templates, ajax and/or the developer is just in the habit of naming all of the tables with the same ID - it's a different page, so why not?

As the storage code works now, it tries to make sure each table is unique by saving it's url, id and/or index on the page. If I only look for an ID, then every saved parameter, not just "saveSort" will be loaded for different tables.

So while I won't make this change, I can tell you that all you need to do is modify your own copy by setting the url to some constant, any constant... just modify this line:

url = 3; // window.location.pathname;
@TheSin-

This comment has been minimized.

Show comment
Hide comment
@TheSin-

TheSin- Oct 15, 2013

Collaborator

That being said, and I do 100% agree with mottie, seems odd you'd have the same table at a different url anyhow. But couldn't this easily be an option mottie? just a config option that then sets it to a constant, the default obviously staying the same as it is now.

url = window.location.pathname;

if (c.urlconstant !== "undefined") {
      url = c.urlconstant;
}

Or something simple like that, not only could it then be a constant but you could then group tables. aka in my site I have lots of tables that are close to the same just different products or mfgs. It's be nice to keep the sort between them, using this approach I could use the same constant per grouping in the init phase. Just a suggestion and it doesn't really chance how it works now.

Collaborator

TheSin- commented Oct 15, 2013

That being said, and I do 100% agree with mottie, seems odd you'd have the same table at a different url anyhow. But couldn't this easily be an option mottie? just a config option that then sets it to a constant, the default obviously staying the same as it is now.

url = window.location.pathname;

if (c.urlconstant !== "undefined") {
      url = c.urlconstant;
}

Or something simple like that, not only could it then be a constant but you could then group tables. aka in my site I have lots of tables that are close to the same just different products or mfgs. It's be nice to keep the sort between them, using this approach I could use the same constant per grouping in the init phase. Just a suggestion and it doesn't really chance how it works now.

@Mottie

This comment has been minimized.

Show comment
Hide comment
@Mottie

Mottie Oct 15, 2013

Owner

Well, I try to keep an open mind. If that'll work for you as an option, then I don't have any problem adding it.

Owner

Mottie commented Oct 15, 2013

Well, I try to keep an open mind. If that'll work for you as an option, then I don't have any problem adding it.

@TheSin-

This comment has been minimized.

Show comment
Hide comment
@TheSin-

TheSin- Oct 15, 2013

Collaborator

I haven't testing that code and obviously it's missing all the config section, was just making a suggestion that could make everyone happy. I'm okay either way I have my work arounds for this, but I was just saying I could see it being useful I personally could use it. Then I could finally have a user prefs code that saves the save sort to a db and reloads it for a specific type which is something I have being wanted to do for my users.

Collaborator

TheSin- commented Oct 15, 2013

I haven't testing that code and obviously it's missing all the config section, was just making a suggestion that could make everyone happy. I'm okay either way I have my work arounds for this, but I was just saying I could see it being useful I personally could use it. Then I could finally have a user prefs code that saves the save sort to a db and reloads it for a specific type which is something I have being wanted to do for my users.

@Francks11

This comment has been minimized.

Show comment
Hide comment
@Francks11

Francks11 Oct 15, 2013

Indeed, being able to specify this option would be really nice :-)

I do not like the idea of ​​making changes directly in the copy because if you update, I would have to redo this update.

Thank you.

Francks11 commented Oct 15, 2013

Indeed, being able to specify this option would be really nice :-)

I do not like the idea of ​​making changes directly in the copy because if you update, I would have to redo this update.

Thank you.

@Francks11

This comment has been minimized.

Show comment
Hide comment
@Francks11

Francks11 Oct 17, 2013

When this feature will be available?

Francks11 commented Oct 17, 2013

When this feature will be available?

@Mottie

This comment has been minimized.

Show comment
Hide comment
@Mottie

Mottie Oct 18, 2013

Owner

Hi @Francks11!

I am trying for today... that being said, I would like to get feedback on this proposed change.

Since the storage is saving data per page and per table, maybe it would also be nice to modify the table index. I probably went overboard, but here is what I'm thinking:

ts.storage = function(table, key, val, options){
  var d, k, ls = false, v = {},
    c = table.config,
    id = options && options.id || $(table).attr(options && options.group ||
      'data-table-group') || table.id || $('.tablesorter').index( $(table) ),
    url = options && options.url || $(table).attr(options && options.page ||
      'data-table-page') || c && c.fixedUrl || window.location.pathname;

So now if you have written a custom widget, you can provide options (id & url) or just add a table data attribute:

$.tablesorter.storage( table, key, value, {
  // table id/group id
  id  : 'group1',
  // table pages
  url : 'page1',
  // group is overridden by the id option, but sets the table attribute with the ID
  group: 'data-table-group',
  // page is overridden by the url option, but sets the table attribute with the page/url
  page: 'data-table-page'
});

Or, as @TheSin- proposed, just setting a fixedUrl option (yeah I renamed it)

Overkill much?

Owner

Mottie commented Oct 18, 2013

Hi @Francks11!

I am trying for today... that being said, I would like to get feedback on this proposed change.

Since the storage is saving data per page and per table, maybe it would also be nice to modify the table index. I probably went overboard, but here is what I'm thinking:

ts.storage = function(table, key, val, options){
  var d, k, ls = false, v = {},
    c = table.config,
    id = options && options.id || $(table).attr(options && options.group ||
      'data-table-group') || table.id || $('.tablesorter').index( $(table) ),
    url = options && options.url || $(table).attr(options && options.page ||
      'data-table-page') || c && c.fixedUrl || window.location.pathname;

So now if you have written a custom widget, you can provide options (id & url) or just add a table data attribute:

$.tablesorter.storage( table, key, value, {
  // table id/group id
  id  : 'group1',
  // table pages
  url : 'page1',
  // group is overridden by the id option, but sets the table attribute with the ID
  group: 'data-table-group',
  // page is overridden by the url option, but sets the table attribute with the page/url
  page: 'data-table-page'
});

Or, as @TheSin- proposed, just setting a fixedUrl option (yeah I renamed it)

Overkill much?

@Francks11

This comment has been minimized.

Show comment
Hide comment
@Francks11

Francks11 Oct 18, 2013

Hi @Mottie

It is good for me :-). Perfect.

This is really much more than what I expected.

Thanks

Francks11 commented Oct 18, 2013

Hi @Mottie

It is good for me :-). Perfect.

This is really much more than what I expected.

Thanks

@TheSin-

This comment has been minimized.

Show comment
Hide comment
@TheSin-

TheSin- Oct 18, 2013

Collaborator

overkill or super customizable? :)

If I get a chance today I'll try and run it through the ringer, I've been so busy on other projects lately :( I really can't wait to get back on this one!

Collaborator

TheSin- commented Oct 18, 2013

overkill or super customizable? :)

If I get a chance today I'll try and run it through the ringer, I've been so busy on other projects lately :( I really can't wait to get back on this one!

@Francks11

This comment has been minimized.

Show comment
Hide comment
@Francks11

Francks11 Oct 18, 2013

I would say super customizable :-)

Francks11 commented Oct 18, 2013

I would say super customizable :-)

@Mottie Mottie closed this in 340fdf0 Oct 18, 2013

@Mottie

This comment has been minimized.

Show comment
Hide comment
@Mottie

Mottie Jan 19, 2014

Owner

I forgot to mention, if you use the storage utility to get a stored value AND need to set the storage options, set the value parameter to null.

// Get key's value from storage with set options
// $.tablesorter.storage( table, key, value, options );
$.tablesorter.storage( $('table')[0], 'someVariable', null, {
  id  : 'group1'
  url : 'page1'
});

Of course, if saving a value, just set the value parameter to whatever value you want (which also accepts empty strings).

I'll include this detail in the upcoming API docs that I'm adding to the main documentation page.

Owner

Mottie commented Jan 19, 2014

I forgot to mention, if you use the storage utility to get a stored value AND need to set the storage options, set the value parameter to null.

// Get key's value from storage with set options
// $.tablesorter.storage( table, key, value, options );
$.tablesorter.storage( $('table')[0], 'someVariable', null, {
  id  : 'group1'
  url : 'page1'
});

Of course, if saving a value, just set the value parameter to whatever value you want (which also accepts empty strings).

I'll include this detail in the upcoming API docs that I'm adding to the main documentation page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment