Reputation: 532
I want to create an application with stats, i.e. american football players.
I have my database and I can query things like "passing yards", "rushing yards", etc and I sort them out from highest to lowest. Then on the client-sideI am considering letting the user re-sort the results (using javascript).
So far trivial, but let say when selecting passing yards I get 100 results, then query returns only the first 20 on the first page and give a more, or next option. Now if I let the user on the client side re-sort by himself, then he will sort the first 20 and can get confused thinking the top 20/100 somehow sorted are the lowest 20/100 too. I could also send the 100 results and show only 20 using javascript, but this may take a while to load if the list increases.
Plus if I consider that if I let them sort by highest/lowest maybe I want to let them sort by passing yards, by team, etc or even select a team, position, etc.
I am thinking php and make every sorting a query, but is there other ways that I don't know?
Note: I am a true beginner.
Upvotes: 1
Views: 199
Reputation: 41
Well there are a lot of ways to retrieve and show data on a dynamic web project, but that is out of your scope of information. If I were in your shoes I would use java (Java EE) using struts with hibernate, and probably spring on top just to make it easier, but I am guessing you don't know those and are limited to javascript and php.
I would say making query's for each type of result the user could possibly enter would be tedious but probably your best option given that your are a beginner. This is not a "best practice" but if this is just a small project that yourself is undertaking I think it will work.
Upvotes: 2
Reputation: 5263
If you do not allow to see all results on the same page, you should get new data each time user initiates sort (whether with page reload, or with XHR). If you show 20 rows out of 100 and allow client side sort, results will most likely be incorrect.
Now if you have all results loaded, you can sort using a comparator. This will work if each key-value(any type) pair will also have a corresponding key-value(String -- we call it "comparator value"), this way you will be able to compare rows with different types of data.
We have a grid widget that takes any arbitrary data and given all results are loaded, can allow user to re-sort by any given column, and for that we use Backbone collection with a comparator function. If you are familiar with Backbone, I can show a source code for this widget. Leave comment if you want.
Upvotes: 3