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

filteredRows #576

Closed
ric79 opened this issue Apr 8, 2014 · 6 comments
Closed

filteredRows #576

ric79 opened this issue Apr 8, 2014 · 6 comments

Comments

@ric79
Copy link

ric79 commented Apr 8, 2014

Hello Mottie,
I'm filtering, sorting and paging server side

In JS

ajaxProcessing: function (ajax) {               
     console.log("myfilteredRows: " + ajax.myfilteredRows);
     if (ajax && ajax.hasOwnProperty('data')) {
          return [ajax.total_rows, ajax.data ];
      }
}

The output is output: '{startRow} - {endRow} | {filteredRows} [ {totalRows} ]',

How can I update {filteredRows} using ajax.myfilteredRows?

Riccardo

@Mottie
Copy link
Owner

Mottie commented Apr 8, 2014

Hi @ric79!

If your ajax is returning data with myfilteredRows then you can just set the output using the same variable name (in curly brackets; see issue #326 for more details):

output: '{startRow} - {endRow} | {myfilteredRows} [ {totalRows} ]',

@ric79
Copy link
Author

ric79 commented Apr 8, 2014

I read that issue and changed the code without luck. I'm using bootstrap theme as your example

I mean, if ajaxProcessing is only returing total_rows and data, how can tablesorter know the myfilteredRows value?

...
ajaxProcessing: function (ajax) {               
    $('#loadingModal').modal('hide');       
    ajax = {
      "data": [
          [9, "AA", "BB", "CC"],
          [10, "AA", "BB", "CC"],
          [11, "AA", "BB", "CC"]
      ],
      "myfilteredRows": 3,
      "total_rows": 100
    };

    if (ajax && ajax.hasOwnProperty('data')) {
        console.log(ajax.myfilteredRows);
        return [ajax.total_rows, ajax.data ];
    }
},
container: $(".pppp_ts-pager"),
cssGoto: ".pppp_pagenum",
output: '{startRow} - {endRow} | {myfilteredRows} [ {totalRows} ]',
...

Whith this code in page myfilteredRows = 0

@Mottie
Copy link
Owner

Mottie commented Apr 8, 2014

It depends on how you return data from the ajaxProcessing script. If you return an array, as above, then there isn't any way to get the extra data. Instead, return an object.

Sorry, but the object does need to follow this format (use "rows" instead of "data" and "total" instead of "total_rows")

ajax = {
    "rows": [
        [9, "AA", "BB", "CC"],
        [10, "AA", "BB", "CC"],
        [11, "AA", "BB", "CC"]
    ],
    "myfilteredRows": 3,
    "total": 100
};

if (ajax && ajax.hasOwnProperty('rows')) {
    return ajax;
}

I think I better update the docs to make this more clear!

@ric79
Copy link
Author

ric79 commented Apr 8, 2014

Ok, now it's working.

But the number of pages is still 10 (with pagination 10 rows per page).
Now, if I'm returning just 3 rows, the "Select page number" should just have 1 entry, instead of 10

It seems to me that I have to rewrite in this way:

...
ajaxProcessing: function (ajax) {               
    $('#loadingModal').modal('hide');       
    ajax = {
      "rows": [
          [9, "AA", "BB", "CC"],
          [10, "AA", "BB", "CC"],
          [11, "AA", "BB", "CC"]
      ],
      "originalTotal": 100,
      "total": 3
    };

    if (ajax && ajax.hasOwnProperty('rows')) {
        return ajax;
    }
},
container: $(".pppp_ts-pager"),
cssGoto: ".pppp_pagenum",
output: '{startRow} - {endRow} | {totalRows} [ {originalTotal} ]',
...

Paging is then ok.

@Mottie
Copy link
Owner

Mottie commented Apr 8, 2014

If you want to return rows or headers (optional), they must be named within the returned object as "rows" and "headers". The total number of pages is required, and must be named "total":

{
    // optional, but if included, it MUST be named "headers"
    "headers" : [ "Numbers", "Value 1", "Value 2", "Value 3" ],
    // optional, but if included, it MUST be named "rows"
    "rows": [
        [9, "AA", "BB", "CC"],
        [10, "AA", "BB", "CC"],
        [11, "AA", "BB", "CC"]
    ],
    // required value "total"
    "total": 100,
    // everything else is optional and will be available in the "output" setting
    "myfilteredRows": 3
}

If you can't change the returned ajax from the server, you can just reassign the names within the ajaxProcessing function:

ajaxProcessing: function (ajax) {
    if (ajax && ajax.hasOwnProperty('rows')) {
        ajax.total = ajax["total_rows"];
        return ajax;
    }
}

@ric79
Copy link
Author

ric79 commented Apr 8, 2014

Ok, thanks!!!

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