zhoupan / jmesa

Automatically exported from code.google.com/p/jmesa
0 stars 0 forks source link

RFE: Add totalRows to javascript limit class #204

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Motive: I needed to add a validation not allowing the user to call export 
when the data would have more than X rows. For this, I needed the total 
rows in the table contained and this wasn't available anywhere.

Patch: 

- Add a variable totalRows and access methods to the javascript Limit 
class.
- Add java support code to set the variable.

- For completeness, also added a method Limit.getTotalPages() that works 
like the java code in HtmlUtils.

Original issue reported on code.google.com by carlos.c...@gmail.com on 10 Jul 2009 at 8:59

Attachments:

GoogleCodeExporter commented 9 years ago
Great! I'll take a look at the tomorrow then.

Original comment by jeff.johnston.mn@gmail.com on 11 Jul 2009 at 11:42

GoogleCodeExporter commented 9 years ago
I like the feature but this code will not work when using AJAX. The reason AJAX 
works
with JMesa is that the JavaScript Limit on the client has all the correct 
values and
is never updated by the server. So as a person sorts, filters and pages the 
client
JavaScript Limit is updated and then passed to the server. 

The totalRows is something that is calculated on the server and would have to 
be sent
back to the client for this now. So instead of just returning the HTML we would 
have
to return a more complex object to return the HTML and the things that only the
server knows that changed.

I guess I was thinking that the functionality you are looking for would be done 
with
a custom toolbar (which is very easy to put together). 

But I do not want to dismiss your approach as the more information the client 
has the
more kinds of things we can do in general!

I could accept the patch for now and then put this as a limitation as the 
solution is
apparent. Lets think about it for a couple days!

Original comment by jeff.johnston.mn@gmail.com on 14 Jul 2009 at 3:53

GoogleCodeExporter commented 9 years ago
Pardon me, but as far as I can see his works with ajax :)

The limit is updated in the HtmlSnippetsImpl.initJavascriptLimit() method, 
called 
when the table is refreshed through ajax.

Patch for HtmlSnippetsImpl.java:

public String initJavascriptLimit() {
...
+        html.tab().append("jQuery.jmesa.setTotalRowsToLimit('" + limit.getId() 
+ 
"','" + limit.getRowSelect().getTotalRows() + "')").semicolon().newline();
...
}

I tested this with a big table, and after applying a filter that returned only 
one 
row the limit was refreshed accordingly: totalRows was updated with the value 1.

But there have been occasions where I haven't seen much beyond the tip of my 
nose 
and I wouldn't wonder this is one of them ;)

Original comment by carlos.c...@gmail.com on 14 Jul 2009 at 4:54

GoogleCodeExporter commented 9 years ago
Hey, your right! I put an alert in the snippets file and it worked using AJAX. 
I had
no idea. I think at one point I even tested this out, but that was before I was 
using
jQuery. That or I am losing my mind :). Either way it works. Thats great news. 
I will
check in your patch tonight then!

Original comment by jeff.johnston.mn@gmail.com on 14 Jul 2009 at 7:58

GoogleCodeExporter commented 9 years ago
Added to the trunk and will go out in the next release. Probably by the end of 
the
month. I don't mind keep doing these incremental changes and I like to release 
as
soon as possible.

Original comment by jeff.johnston.mn@gmail.com on 15 Jul 2009 at 2:14

GoogleCodeExporter commented 9 years ago

Original comment by jeff.johnston.mn@gmail.com on 15 Jul 2009 at 2:14