Solved

JSON Table click sort not working

Posted on 2015-01-18
8
213 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
8 Comments
 
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:
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 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.
0
 
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.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 32

Accepted Solution

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now