Welcome to the sixth part of a fourteen part series detailing how to create database forms in HTML. In this article, we will discuss sorting and its various functions as well as the boolean values that come as a result. Please join us as we tackle these issues.
Sorting for Database Forms with HTML (Page 1 of 4 )
Appreciation of Sorting
When data is retrieved from a database, you can have it sorted by the database engine before you receive it at the client. Sorting, whether done by the database engine at the database server or by the client, is based on one column. That is, one column is sorted alphabetically while the others are not sorted. It can only be this way, since the data exist in rows and a row must always have the same elements. If you exchange the positions of two elements in a column during sorting, you are exchanging their corresponding rows to the same positions as you have done for the elements of the column, otherwise the integrity of each row will not be maintained. So you will hardly see an ascending or descending order in more than one column.
The sort() Function
There are different algorithms for sorting an array of strings. Time-critical client applications often use the algorithm called Quicksort, which is very efficient. The application for this article is a time-critical client one, so the function I use is an implementation of the Quicksort algorithm. I wrote an article for www.devarticles.com titled “Quicksort.” In this article, I explain how the Quicksort function operates. You can read the article if you want to know how the function operates. Here, I will simply tell you what you send into the function and what you get out of it.
When the user clicks the Sort button, the following function is called:
//display a dialog box that prompts the user for input of title – “Name” is default
var title = prompt("Enter the Title of the Column for Sorting", "Name");
if ((title != null)&&(title != ""))
var titleInx = getColumnIndex(title); //the column index of the recordset
if (titleInx == 6)
alert(‘The title does not exist - type with the right case without abbreviation.');
quickSort("0", (numberOfRows - 1), titleInx);
setTitleBool(title); //indicate in the titleBoolArr array that the column with the title is sorted