• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

JSON Table click sort not working

Last summer I built this table with the help of experts on this site.  The click sort doesn't work nor does the search and the number of items to view.  Any idea what is wrong with the page?  It displays the data beautifully.
Bob Schneider
Bob Schneider
5 Solutions
Robert SchuttSoftware EngineerCommented:
It seems to me you're not handling the paging/searching in your code at all. Even though I obviously can't see your server-side code, the returned json data would have to contain some extra info as well for that to work.

However, it all works perfectly client-side when I remove the following line from the settings:

Open in new window

Bob SchneiderCo-OwnerAuthor Commented:
Interesting.  But if I remove that then I can't change gender or category.  I am a json/ajax newb.  I think it's time to do some reading.  I was under the impression the table functionality was all client-side and that my asp just prepped the data to be displayed.
Robert SchuttSoftware EngineerCommented:
As far as I can tell, your example page does not contain the code from earlier questions regarding changing gender and category.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Robert SchuttSoftware EngineerCommented:
Looking at another page on your website that does have the category selection, without testing locally, it seems to me that part should still work fine: when the selection changes, the data url is adjusted and the data gets refreshed. It's just the paging and filtering that gets done client-side. I'm guessing with the limited amount of data you have per page that's exactly how you want it, refreshing from the server for each page of data (and filtering action) in this case would be more work to program and probably slower for the user.
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Since you need to use bServerSide = true, you'll need to handle the sorting on the server side. you shouldn't need to change any client side code, just in results_array.asp, you'll need to check for which column is being sorted on, then add an order by in your sql with that column.

to determine the column you'll need to look at the iSortCol_0 field being passed over, this'll be the index of the column (keep in mind it's a zero based index system), so if it comes back as 2, it would be the "School" column. You can also determine if it's ASC/DESC by looking at the sSortDir_0 field. so you're code may look something like:

iSortCol = Request("iSortCol_0")
sSortDir = Request("sSortDir_0")

'-- sanitize fields to make sure they are valid values
if iSortCol = "" or not isNumeric( iSortCol ) then iSortCol = -1
if LCase( sSortDir ) <> "asc" and LCase( sSortDir ) <> "desc" then sSortDir = "asc"

sortBy = "name"    '-- default sort by column
select case iSortCol
     case 0: sortBy = "place"
     case 1: sortBy = "name"
     case 2: sortBy = "school"
     case 3: sortBy = "points"
end select

sql = "select data from table where conditions = met order by " & sortBy & " " & sSortDir

Open in new window

to take advantage of all of the client side data table features, you would need to re-wire how you send the data back from the 2 dropdowns. more work now but more efficient later on, unless you're going to continue to allow for custom filtering on your table
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You are much better off to let the javascript do the sorting.  Send the data to the browser and let datatables do the sorting on the client. It will be a lot faster and easier on your server.
Bob SchneiderCo-OwnerAuthor Commented:
I am going to close this out until I have time to implement the advice.  Thanks for all of your help!
Bob SchneiderCo-OwnerAuthor Commented:
Thank you very much everyone.  I will let you know how it comes out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now