?
Solved

JSON Table click sort not working

Posted on 2015-01-18
8
Medium Priority
?
230 Views
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.
0
Comment
Question by:Bob Schneider
[X]
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
8 Comments
 
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:
bServerSide:true,

Open in new window

0
 

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.
0
 
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.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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.
0
 
LVL 33

Accepted Solution

by:
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
0
 
LVL 53

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.
0
 

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!
0
 

Author Closing Comment

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

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

777 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