Sorting Columns in a Grid When Order isn't Clear

Suppose I query a database table for some data and display it in a table where I can set the sorting of each column. Here are three scenarios where the data either doesn't have an obvious order, or what we display is not in the database:

Case 1: Suppose we store usernames and not full names, but we only display full names in the table. Is there an easy way of being able to sort the table based on the full name without having to also save the full name in the database?

Case 2: Supposed we store two numerical values x and y in the database, and we display x/y. How can I sort by the value of x/y?

Case 3: Suppose that we have some text values each associated with an id, but that the id (for whatever reasons) cannot be used to order the text by significance. Is there a way to sort the text in some predetermined but custom order, without having to save information in the database about what this custom order is?

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer
    1. Possible? yes.  Easy? not really.  It requires a workaround, along the lines of querying the whole table into one local variable, iterating over that array to create a second "translated" local varaible, then creating a sorted data subset from that.  Obviously this requires it to be a fairly limited data set (no more than a few hundred items at the largest, preferably).
      My preferred method, however, is that if the column is sorted on username, then display the full name along with the username (rich text grids FTW) in a way that will make sense to the user.

    2. When you say "x/y", do you mean literally the string of "x", & the "/" sign, then "y", or do you mean you'd be displaying "x divided by y"?  In that case, you might be able to accomplish the heavy lifting necessary using a view.

    3. My suggested approach for this is to also add an "Order ID" column, which is not the primary key ID (and not related to it), but just an ID strictly used for ordering of items in the table.
Reply
  • +1
    Certified Lead Developer
    1. Possible? yes.  Easy? not really.  It requires a workaround, along the lines of querying the whole table into one local variable, iterating over that array to create a second "translated" local varaible, then creating a sorted data subset from that.  Obviously this requires it to be a fairly limited data set (no more than a few hundred items at the largest, preferably).
      My preferred method, however, is that if the column is sorted on username, then display the full name along with the username (rich text grids FTW) in a way that will make sense to the user.

    2. When you say "x/y", do you mean literally the string of "x", & the "/" sign, then "y", or do you mean you'd be displaying "x divided by y"?  In that case, you might be able to accomplish the heavy lifting necessary using a view.

    3. My suggested approach for this is to also add an "Order ID" column, which is not the primary key ID (and not related to it), but just an ID strictly used for ordering of items in the table.
Children