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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.