I'm trying to alphabetically sort a table in javascript (that is actually automatically populated from an XML file). The table is a list of words in 3 languages, one of which is Italian. What is happening is, the sort() function I am using to order the words is not considering accented characters, such as:
that should be sorted exactly as their corresponding ASCII characters A,O,U,E,I
Categories and names are both properties of one and the same array element. I have the following compare function to sort the outer categories.
function compareCats(a, b) { a = a.category; b = b.category; if(a == b) return 0; else if(a b) return 1; else return -1; }
This is working fine. But I really would like to include the inner names in the compare function without changing the structure of the array - if it could be possible. If not - what would be an efficient way to solve the problem?
I've been trying just about every sort function I could google but they do not work becuase I am building the table I want to sort dynamically from XML - then appending it to the page using innerHTML. No HTML gets written to the page, hence there are no HTML values to iterate through to sort. Does anyone know a way to capture values that have been extracted from the XML file and then sort them based upon the users selection?
I am trying to duplicate the graphic effect used in Outlook for sorting Columns, click on it the first time and it sorts descending, click again and it clicks ascending, click on another field and the original image returns and that field is now sorted. I can do the actual sort on the back-end using JSP, and really only need to make the script smart enough to know that another column has been clicked.
A couple of items for consideration, I am working on an intranet, and must support Version 4 browsers. The server I am using is an Iplanet V6.0 server.
After inserting this new table row i would like to sort the table by the first column (or any attribute of the first columns td elememts). I tries some Plugins like tinysort right now, but they only sort the "fixed" rows, not the dynamicly added.
The table should be sorted automaticly, the user should not be able to sort it.
The code sortes/reverses the rows of a table with data upon the correspondent chosen column.
Uses DOM methods
Tested in IE6, NS7, Firefox, Moz 1.7, Opera 7.5 on XP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>sort_reverse table</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <style type="text/css"> <!-- td { background-color: #CCCCCC; } --> </style> <script language="JavaScript" type="text/JavaScript"> function sortIt(w){ r=document.getElementById('tab').rows;//the root var oRows = new Array()//set the rows to be removed as an array of cloneNodes var iRows = new Array()//set those rows' indexes as array for(var i=1;i<r.length;i++){ oRows[i]=r[i].cloneNode(true); iRows[i]=r[i].rowIndex; } q=w.parentNode.cellIndex;//set the column index of cells content var oCol = new Array()//set the string content of column cells as array var vCol = new Array()//set the "compare" array for a future sort/reverse for(var i=0;i<iRows.length;i++){ oCol[i]=[r[i].cells[q].firstChild.nodeValue,iRows[i]]; vCol[i]=[r[i].cells[q].firstChild.nodeValue,iRows[i]]; } oCol.shift();//remove the first element (the content of the cell in first row vCol.shift();//do the same with "compare" array oCol.sort();//sorts the content array if(vCol.toString()==oCol.toString()){oCol.reverse()}//if the content was already sorted, reverse for(var i=1;i<r.length;i++){ r[i].parentNode.replaceChild(oRows[oCol[i-1][1]],r[i]) }//writes the rows in a sorted/reversed order } </script> </head> <body> <table id="tab" width="400" border="0" cellspacing="2" cellpadding="2"> <tbody> <tr> <td><a href="#" onclick="sortIt(this);return false">SORT/REVERSE</a></td> <td><a href="#" onclick="sortIt(this);return false">SORT/REVERSE</a></td> <td><a href="#" onclick="sortIt(this);return false">SORT/REVERSE</a></td> </tr> <tr> <td>Banana</td> <td>yellow</td> <td>10</td> </tr> <tr> <td>Apple</td> <td>cyan</td> <td>20</td> </tr> <tr> <td>Cherry</td> <td>blue</td> <td>40</td> </tr> <tr> <td>Drops</td> <td>green</td> <td>30</td> </tr> </tbody> </table>
I have a table that I am trying to implement sortTable so i can sort the Table by the Column Headers. I have come across a few different ways to implement sortTable, but none of them seem to be working for me. here is the first way I tried to implement it (in the <table class =" ">) this is not the way I would like to do, as I have CSS defined class "halloween" I would like to use (unless u can implement 2 classes?) anyways it is still not working but here is the code
I've used jQuery ajax and .post a lot, and several times within the very application that i'm having issues with, but I've never run into this issue before.I've got a table of items and categories, sorted by a sort number. in the same cell that the sortnum input is in, there is a span with a status id that differentiates between items and categories so i can modify the correct records in the correct database table.First, i select all of the inputs and then sort them by the value of the input. next, i loop through the inputs, creating two arrays: one array contains the type of entry, and the other contains the id of the entry.
After the loop, i join each array into its own variable, sortlist and typelist. Next, i perform a .post passing the two lists to my server.The problem is, on the server side, those two variables are getting a "[]" appended to the end of them, and since i'm working in coldfusion, the only way to get data from them is with evaluate. I can get by using evaluate(), but i'd rather not have to.So far i haven't found a way to get the value of this variable. has anyone else ran into this issue and found a solution?
I am using Jquery and the tablesorter plugin to sort a table of information. Within the table i have a column of checkboxes. A user can check the boxes and press the submit button which will $_POST the checked boxes onto the next page. Everything works if i dont sort the table, but if i sort the table and then check a few boxes the $_POST array is empty.
I have a some code that is drawing out regions when a country a selected.I want the regions to order alphabetically, but its not doing it for some reason.PHP Code:
$q=mysql_query("select * from tbl_resorts where Id_show=1 ORDER BY Nom_Rsrt") or die (mysql_error()); while($r=mysql_fetch_row($q))
OK so Ive been using jquery for a little bit now and love it. I am a ColdFusion developer. I have a need where I would like to present the user with a list of categories and the user can drag and drop to sort, but then I need to post this new sort order to the database. So I see there are a ton of cool drag & drop plugins for jquery. I understand how they work and I can get it to work as far as spitting out DIVS or spitting out ULs that can be sorted, but then what? So now they are sorted on my screen and not really part of the form. How do I translate that into something I can do a post to the database with? Do I do an AJAX call every time they drop an item and try to extrapolate the sort order on that item after they drop it? Do I populate a hidden form field with the constantly updating sort order list? MAybe a list of ID's? How does everyone else go about this this task? I'm sure there is more than one way and I'm sure this is a common task.
function sortBy(prop,arr) { sortProp=prop; arr=arr.sort(sortFunc); }
function sortFunc(part1,part2) { if (part1[sortProp]>part2[sortProp]) retVal=-1; else if (part1[sortProp]<part2[sortProp]) retVal=1; else retVal=0; return retVal; }
This however allows me to sort only by one criteria. I need to sort by weight first and then by height for those items that have the same weight.
Suppose I have a page with a set of hyperlinks on it. Each time a hyperlink is clicked a new window is opened. What i basically want is the following : I want a counter at the client side which increments each time the user clicks one of those links. At the bottom of the page I'll put a button which should be used to send the value of the counter away.
The problem is I only know server side scripting and have no idea on how to implement such a counter on the client side. I even wonder if it's possible to detect when a link is clicked. The links may be buttons if that would make it easier, it's just that i don't want to reload the page each time a link is clicked but only at the end when the button at the bottom would be clicked.
I'm working on displaying a list of events on my site and need to display them in ascending order. i've got an xml document that looks like this(with multiple events obviously,Can anyone help me with sorting this? So far I have it displaying only events that are occuring after the present date(currentDate). How would I go about displaying them so that the events displayed will be in the order of the earliest date displaying first?
I can't find any syntax for how to sort something with JQuery but here's a description of what I'm wanting to do.[code]
1. Start with the list of matches, in order. Introduction comes first. 2. Sort the segments by segmentOrder first, segmentNum second. 3. Insert each segment after match #(segmentOrder), in the same order.
I check the web and they only show you how to sort the whole array. I would like to be able to sort the subset of the 2D array.How would I sort the sub array independently. So only the a's together, then only the b's together, etc.
For example when row two is clicked I would like the table to reorder a, b, c, d <table><tr> <td>col 1</td> <td>col 2</td> <td>col 3</td> <td>col 4</td> </tr><tr> <td>b</td> <td>a</td> <td>d</td> <td>c</td> </tr><tr> <td>z</td> <td>x</td> <td>y</td> <td>w</td> </tr></table>
I have a list of records from my database being displayed on this page. I want to be able to sort the columns. Typically, I do this with an HTML table, but was wondering if there is a way I can setup the below code using jQuery to allow for the column headers to be sortable? I have an icon to sort up and an icon to sort down.My goal is to allow the user to sort the data without a page refresh.
<div class="header"> <ul> <li style="width: 20%;">Customer Number <img src="images/iconSort.gif" /></li>