Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


JSON Table click sort not working

Posted on 2015-01-18
Medium Priority
Last Modified: 2015-02-03
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.
Question by:Bob Schneider
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 1200 total points
ID: 40557392
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


Author Comment

by:Bob Schneider
ID: 40557611
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.
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 1200 total points
ID: 40557627
As far as I can tell, your example page does not contain the code from earlier questions regarding changing gender and category.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 1200 total points
ID: 40557819
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.
LVL 34

Accepted Solution

Big Monty earned 400 total points
ID: 40557904
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
LVL 54

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 400 total points
ID: 40558377
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.

Author Comment

by:Bob Schneider
ID: 40586231
I am going to close this out until I have time to implement the advice.  Thanks for all of your help!

Author Closing Comment

by:Bob Schneider
ID: 40586233
Thank you very much everyone.  I will let you know how it comes out.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question