So I've done quite a lot of research about this particular topic, and I still find myself somewhat confused as to the best approach. There are two parts to my question.
1.) Basically my page is accessing a MySQL music database which holds the entire discography by a particular artist. There are literally 1000's of items. The page's function is to display all items and sort them by a particular value in the array (which the user chooses from a pre-defined list) like title, date released, catalog number, category, etc.
From what I understand, there are two ways I could achieve the display & sorting. Once the user loads the page, the PHP could output the discography array immediately, echo it into a javascript object, then use javascript to do the sorting once the user clicks a button.
OR
After the user clicks a button, I could use AJAX to send the value by which the user wants all items sorted, use PHP ** or database server sorting, like ORDER BY ** to do the sorting and output the array in JSON. An array sorted by pagename, for example, would look like something this:
var discography = [
{"id":"1",
"pagename":"item100001",
"category":"Albums",
"Label":"Atlantic",
"title":"Awesome Album",
"date":"July 2, 1998",
"country":"United States",
"catalog":"666 3333 44444",
"format":"CD"},
{"id":"12",
"pagename":"item100002",
"category":"Albums",
"Label":"Epic",
"title":"Fun Music",
"date":"January 22, 1992",
"country":"United Kingdom",
"catalog":"333 4444 5555",
"format":"Cassette"},
{"id":"3",
"pagename":"item100003",
"category":"Single",
"Label":"Atlantic",
"title":"Cool Single",
"date":"October 12, 1988",
"country":"United States",
"catalog":"444 5555 66666",
"format":"CD"}
];
Which I could then manipulate by jquery to output as html and display the items on the page.
The user should be able to sort and re-sort the items by whatever value they want, not just once.
Perhaps this question is oversimplifying the premise, but which is the smarter, faster and more efficient approach to array sorting? Server-side sorting (using AJAX and outputted as JSON) or Javascript? If it's server-side, I'm confident I'd know how to write functions to sort the data properly.
But if the answer is Javascript, that brings me to my second question.
2.) I have found plenty of wonderful javascript sorting functions out there, but I keep reading about the issue of "stable" versus unstable sorting in Javascript. Would this issue even apply? I definitely need this to be consistent across all browsers. Merge Sort is apparently a wonderful answer to this quandry, but since I need to sort by a particular field (category, date, etc), I would need a little direction on how to adapt the function to my purpose. But if I can do safe, consistent sorting without merge sort, then I'll just do that.
If you've read this far I appreciate it. Any help would be welcomed!