JSON Table click sort not working

Posted on 2015-01-18
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 300 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 300 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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 300 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 33

Accepted Solution

Big Monty earned 100 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 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 100 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Tutorial help 2 40
How do I post more than 1 item to php backend 24 32
Converting Stored Procedure to SQL Statement 5 44
center navbar (navigation menu) on web page 3 23
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

726 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