2

I'm trying to determine what would be the most efficient/recommended way of doing this--I have a table consisting of MySQL table elements that are generated by PHP upon page load. There are four columns, but right now I'm concentrating on sorting them by date added-if the user clicks the column header link "Date".

So my options are either using AJAX w/ PHP to contact the database, sort the entries by date, generate the table code and send it back to replace the table in real time. Or, I could use JQuery to build an array of the rows and determine the order based on the date (which will be a little bit of work because the dates are formatted like 'January 16, 2012') and then resort the rows accordingly.

Which of these options, or if you have a better idea for working this, would you recommend to use?

Thanks!

1
  • How many elements are you expecting? Commented Feb 16, 2012 at 21:16

4 Answers 4

2

if you have all the data loaded in your page so use javascript, since it will save up make an additional call to the server, hence more efficient.

if your table shows part of the data (ie you have "pages" -> next, prev...) then use ajax, return the results in a json object and sort while fetching using MySQL

Sign up to request clarification or add additional context in comments.

1 Comment

if table have too much rows then sorting on client-side may be worst because of some rendering problems and DOM problems. Server CPUs are better than client CPUs so sorting on server may be better for that situation
2

Take a look at the jQuery plugin Tablesorter. You can find it here:

http://tablesorter.com/docs/

1 Comment

I'm trying to avoid using plugins for this project, as my Javascript skills are not quite to par and I'd like to code as much by hand as possible. But that is very handy and I'll surely bookmark for future projects. Thanks!
1

it is change for situation. i mean, if you dont have too much rows for sorting or if you dont have paging then sorting on client-side may be better. But if you have much more rows or paging functionality then you should do sorting on server-side.

1 Comment

I think I'll go with client-side -- there won't be a large amount of rows so I think it'll suffice. Thanks!
1

Use a plugin, e.g. http://tablesorter.com/docs/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.