I have a web app with data in a grid. The user can reorder the columns, and the server can change which columns exist. I would like to save the user's column order in a cookie and restore it on page load.
More formally, I have two arrays of unique IDs (strings) called user_columns
and server_columns
. I would like to reorder server_columns
such that I respect all of the ordering information from user_columns
, and as much from server_columns
as possible. How do I do this? What's a reasonable formal definition of "as much as possible"?
My analysis so far:
One aspect of the problem is trivial: if the server removes some columns, delete the corresponding entries from user_columns
. Any information about the ordering of columns which are no longer there is moot. The problem then becomes one of merging two potentially conflicting sets of ordering information.
This corresponds to a family of problems from voting theory: given a set of ballots, each of which contains a partial order between the candidates, produce a complete ordering of the candidates which in some sense reflects the ballots.
This leads me to think that I might get a workable solution by applying e.g. the Schulze Method or Ranked Pairs to a sufficiently rigged set of ballots based on user_columns
and server_columns
. For UX reasons, breaking ties by inserting new columns last (to the right) seems like a good idea to me.
Does this sound like it's on the right track?
Note also that we can consider three kinds of comparisons: A and B are both in user_columns
, one of them is, or none of them are. The former and latter kinds are easily resolved (refer to user_columns
and server_columns
, respectively); the one in the middle, and its interactions with the latter, are the tricky parts.
user_columns
andserver_columns
are arrays, and the server can change the order of columns, i.e. if A and B both occur inserver_columns
in two consecutive page loads, they can occur in two different orders. The more interesting property, I think, is thatuser_columns
andserver_columns
can disagree in a single page load, but in either case I think the answer is "yes" :) – Assassinateserver_columns
and respectsuser_columns
completely (zero inversions w.r.t.user_columns
)? Because that how I interpret the question. – Edna