• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2146
  • Last Modified:

JQuery server side data table sorting example in Java

Hi Experts,

I am working on JQuery server side data table that needs to be sorted for each column.
All the data are coming from DB and each column in the data table should be sortable.
Can anyone show me a small example in Java?

thanks in advance.
3 Solutions
Michel PlungjanIT ExpertCommented:

jQUery is client side, JAVA is server side - no need to do anything special on the server since the client is perfectly capable of sorting any table

Plain javascript: http://www.kryogenix.org/code/browser/sorttable/
jQuery UI : http://jqueryui.com/sortable/ using  $('tbody').sortable();
Rainer JeschorCommented:
sorry but I got a little bit confused.
jQuery is client side Javascript code - nothing on the server.
Java <> Javascript

Do you want to sort the datatable on the clientside using Javascript?

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I think what he means is he is using http://datatables.net/  and probably using he serverside example http://datatables.net/release-datatables/examples/data_sources/server_side.html where data is coming from a php file.

If your columns are sorting but not correctly, you have to make sure you have told datatables what type of data is in the columns (text, numbers, dates).  If it is not sorting at all, make sure you have sorting on http://datatables.net/release-datatables/examples/basic_init/table_sorting.html

The best thing to do at this point is post a link to your page.  All we need to see is rendered html and your js/jquery code for datatables.  The fact you are using java is not a factor here.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

dkim18Author Commented:
Yes, I meant the server side example here:

I need to create multiple tables with multiple  tabs and I am wondering if there is any example that deal with multiple tables and tabs by using  server side language Jave/JSP.

So far, I followed one example and I created only one data table and when I click column header, the column sorts, but it calls the servlet again(I set debugger). If I have multiple tables(each table associated a long SQL query that takes a few sec, so I want to avoid unnecessary DB call.)

Once the table is filled(from oracle DB), I just want each sortable column client side. If the search box (http://datatables.net/ ) on the top right works client side, that will be nice as well.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You are best off letting us see an example page you created.  You may be better off using your serverside code to generate enough json data for 100 rows, then you let datatables page through the 100 rows of data client side.  If you get to the last page, then use ajax to add another 100 rows of data to the existing json data.    If you keep relying on serverside, it defeats the purpose of using datatables and you may as well just use a table.
dkim18Author Commented:
ah...sorry about not mentioning the reason I can't show you my page. It is an intranet web app and it contains some confidential data.
The total rows are less than 100 and the number of data table will be around 5-6, so each data table has around 20 rows.

I will test those column sorting client side examples this weekend.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You can always use test data.  If you are loading 5 or 6 tables on a page, you may want to load them via ajax where table 2 will not load until table 1 loads.  However, the amount of data is so small, you should be able to simply write your json data then load all tables.  

Test it by saving the rendered html and loading it statically.  If it loads fast, it is probably your queries.  Test just the page that loads data and see what happens.  If that is slow, you may want to post a new question just dealing with how you make your query.  I am always amazed how another point of view can find something I didn't think of.
dkim18Author Commented:
Thanks all!
Ok, I was able to sort and filter in client-side once the data table is loaded.
Now, here is another question that I am facing.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now