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

Pager + Group (tablesorter) no working properly #1035

Closed
fcferreira29 opened this issue Oct 6, 2015 · 8 comments
Closed

Pager + Group (tablesorter) no working properly #1035

fcferreira29 opened this issue Oct 6, 2015 · 8 comments

Comments

@fcferreira29
Copy link

I am having na issue with the use of both the pager and the group,

here is the problem,

on the first page the Month and day is correct but on the second page, the Months and days are the same as the 1st page, so the group is not refreshing from 1 page to the next one,

@Mottie
Copy link
Owner

Mottie commented Oct 6, 2015

Hi @fcferreira29!

The pager + group widget combo does correctly refresh across different pages. I set up this demo. The "Student" column is set up to only group the first 7 letters, or the word "Student", so it doesn't appear to change the group header at all. The other columns show the appropriate group header while paging through the rows.

So, it sounds like the issue you're reporting is about the date. If I had to guess, I would say that either the date parser isn't set up for the date format. For example,

dateFormat : "ddmmyyyy"

or that the "group-date-day" class isn't being used.

If you shared the code being used, it would make it easier to find the issue.

@fcferreira29
Copy link
Author

we are using the pager like this:

.tablesorterPager({
        // target the pager markup - see the HTML block below
        container: $('.pager' + id),
        // target the pager page select dropdown - choose a page
        cssGoto: '.pagenum' + id ,
        // dropdown that sets the "size" option
        cssPageSize: '.pagesize' + id,
        // remove rows from the table to speed up the sort of large tables.
        // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
        removeRows: true,
        // Number of visible rows - default is 10
        size: 100,
        // Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
        savePages: false,
        // output string - default is '{page}/{totalPages}';
        // possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
        output: '{startRow} - {endRow} / {filteredRows} ({totalRows})'

    });

and we set the pager to the eaven if i change to another field, with text, the result is the same.

@Mottie
Copy link
Owner

Mottie commented Oct 6, 2015

The pager code isn't where the issue lies. Please share the tablesorter code, or better yet, modify the demo I shared to show me the problem.

@fcferreira29
Copy link
Author

i changed the github
the date 3 has always the same value

can you tell me what i am doing wrong?

http://jsfiddle.net/yfwwzvL8/232/

@Mottie
Copy link
Owner

Mottie commented Oct 6, 2015

Ok, the date "05-Jan" isn't recognized as a valid date by the built-in parsers; they all expect to see a year. So you'll need to use a custom parser (demo)

$.tablesorter.addParser({
    // use a unique id
    id: 'ddMM',
    is: function () {
        return false;
    },
    format: function (s, table, cell, cellIndex) {
        var months = table.config.widgetOptions.group_months,
            modified = s.replace(/(\d+)-(\w+)/, function (str, d, m) {
                var indx = $.inArray(m, months) + 1;
                // replace month text with one-based index; swap month & date
                return indx > 0 ? indx + '/' + d + '/2015' : str;
            }),
            date = s ? new Date(modified) : s;
        return date instanceof Date && isFinite(date) ? date.getTime() : s;
    },
    type: 'numeric'
});

Make sure the headers have the parser set:

<th class="group-date-day sorter-ddMM">Date 1</th>
<th class="group-date-day sorter-ddMM">Date 2</th>
<th class="group-date-day sorter-ddMM">Date 3</th>

The "80" in the top right column is interpreted as "Jan 01 1980" so that's why the group title is showing "Jan 1".

@Mottie
Copy link
Owner

Mottie commented Oct 6, 2015

Note: Using this javascript acts differently in each browser:

new Date('05-Jan')
  • In webkit browsers, it returns "Fri Jan 05 2001 00:00:00 GMT-0600 (Central Standard Time)" (depending on your time zone)
  • In Firefox, it returns "Invaid Date"
  • In Edge, it also returns "Invalid Date"

So that's why there is code to swap & replace values so the code is parsing a valid date.

@fcferreira29
Copy link
Author

I found what the problem is,

if this is set to true

removeRows: true,

the pager does not work with grouping

the parser you gave me works very well,

thanks

@Mottie
Copy link
Owner

Mottie commented Oct 19, 2015

Ok, thanks for that update... I'll look into updating the group widget.

@Mottie Mottie closed this as completed in cf542ac Oct 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants