Autor |
Beitrag |
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 10:31
Hallo,
ich möchte mit Javascript eine Tabelle sortieren, die gleiche Routine funktioniert mit mehrdimensionalen Arrays bei PHP (Tabellen sind ja im Grund auch mehrdimensionale Arrays) auch...
Ich bekomme vom Internetexplorer (bei FF gehts auch nicht) immer die Fehlermeldung, das in der Zeile, in der der Link steht zum sortieren, ein Objekt erwartet wird...
Hier mal der Code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58:
| <html> <head> <title>Sort-Test</title> <script type="text/javascript" language="javascript"> var columns = Array();
function initColumnData(){ if(document.getElementById("GridView1")){ columns = document.getElementById("GridView1").getElementsByTagName("tr")[0].cells; } }
function sort(column, order){ for(var i = 1; i < document.getElementById("GridView1").getElementsByTagName("tr").length-1; i++){ for(var j = i; j < document.getElementById("GridView1").getElementsByTagName("tr").length; j++){ if(order == "asc"){ if(document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[column].innerHTML > document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[column].innerHTML){ var buffer = document.getElementById("GridView1").getElementsByTagName("tr")[i]; document.getElementById("GridView1").getElementsByTagName("tr")[i] = document.getElementById("GridView1").getElementsByTagName("tr")[j]; document.getElementById("GridView1").getElementsByTagName("tr")[j] = buffer; } }else{ if(document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[column].innerHTML < document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[column].innerHTML){ var buffer = document.getElementById("GridView1").getElementsByTagName("tr")[i]; document.getElementById("GridView1").getElementsByTagName("tr")[i] = document.getElementById("GridView1").getElementsByTagName("tr")[j]; document.getElementById("GridView1").getElementsByTagName("tr")[j] = buffer; } } } } } </script> </head> <body onLoad="initColumnData()"> <table id="GridView1" border="1"> <tr> <td>a <a href="#" onClick="sortTable(0,'asc');">a</a> <a href="#" onClick="sortTable(0,'desc');">v</a></td> <td>b <a href="#" onClick="sortTable(1,'asc');">a</a> <a href="#" onClick="sortTable(1,'desc');">v</a></td> <td>c <a href="#" onClick="sortTable(2,'asc');">a</a> <a href="#" onClick="sortTable(2,'desc');">v</a></td> </tr> <tr> <td>1</td> <td>3</td> <td>2</td> </tr> <tr> <td>2</td> <td>2</td> <td>1</td> </tr> <tr> <td>3</td> <td>1</td> <td>3</td> </tr> </table> </body> </html> |
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 10:41
Wie schau mal:
Wie heißt die Funktion? Und welche Funktion rufst du auf...
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 10:52
Oh, da ist nen table reingerutsch...
Hab ich weggemacht, jetzt sagt der mir, das das Objekt die methode nicht unterstützt...
Hab ich mir gedacht: Vielleicht kann ich die Zeilen nicht als ganzes kopieren, also cell für cell verschieben:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| function sortTable(column, order){ for(var i = 1; i < document.getElementById("GridView1").getElementsByTagName("tr").length-1; i++){ for(var j = i; j < document.getElementById("GridView1").getElementsByTagName("tr").length; j++){ if(order == "asc"){ if(document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[column].innerHTML > document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[column].innerHTML){ var buffer = Array(); for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.lenght; k++){ buffer[k] = document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k]; } for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.lenght; k++){ document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k] = document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k]; } for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.lenght; k++){ document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k] = buffer[k]; } } }else{ if(document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[column].innerHTML < document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[column].innerHTML){ var buffer = Array(); for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.lenght; k++){ buffer[k] = document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k]; } for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.lenght; k++){ document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k] = document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k]; } for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.lenght; k++){ document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k] = buffer[k]; } } } } } } |
Vorteil: Ich kriege keinen Fehler mehr
Nachteil: Es passiert nichts...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 11:03
super..du holst dir das Objekt und schreibst es in den Buffer..
.cells[column].innerHTML fehlt
Dann klappt's auch mit dem Sortieren..
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
Zuletzt bearbeitet von ZeitGeist87 am Di 08.07.08 11:15, insgesamt 2-mal bearbeitet
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:10
dann hab ich einen unbekannten laufzeitfehler in der zeile wo die eine Spalte der anderen zugewiesen wird...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 11:16
Komisch..bei mir funktioniert es tadellos..
Einloggen, um Attachments anzusehen!
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:17
im FF funktionierts bei mir auch...
leider musses im IE funktionieren...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 11:20
gerade getestet..funktioniert ebenso fehlerfrei..
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:23
ööööhhhh...
muss mal kurz neuesten IE installieren...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 11:25
ich hab Version 6 drauf..kein Fehler!
zeig mal deinen Code..
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:30
ich hab noch version 5 drauf...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:37
mit IE7 funktioniert es aber auch nicht...
ICh muss mal grad ultracomparen... deinen und meinen code...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:43
okay, fehler gefunden... nur wieso sortiert dein code auch die anderen spalten, wenn du cells[column] benutzt??
Edit: tuts ja gar nicht... soll es aber...
_________________ 1405006117752879898543142606244511569936384000000000.
Zuletzt bearbeitet von Wolle92 am Di 08.07.08 11:46, insgesamt 1-mal bearbeitet
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 11:46
Spalten?
Bei mir werden nur die Zeilen sortiert..und zwar richtig
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 11:49
also wenn ich eins anklicke bei dir, dann wird das zwar sortiert also steht unter a dann 1, 2, 3...
aber die anderen spalten, b und c, die bleiben wie sie sind..
das ist suboptimal, wenn man eine Liste mit Telefonbuch-ergebnissen sortieren will
es soll ja ncht nur die splate "column" sortiert werden...
_________________ 1405006117752879898543142606244511569936384000000000.
Zuletzt bearbeitet von Wolle92 am Di 08.07.08 11:54, insgesamt 1-mal bearbeitet
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 11:53
What the Hell??
Ich klink mich jez mal aus..denn ich versteh nicht, was du möchtest..warum bitte hast du dann in den anderen Kopfzeilen die Sortierlinks drin?
Dann kannst du gleich alles in eine Zelle schreiben.
Das was du willst ist wahrscheinlich so
Quelltext 1: 2: 3:
| Müller - 123 Vogel - 456 Bauer - 789 |
Alphabetisch sortiert:
Quelltext 1: 2: 3:
| Bauer - 789 Müller - 456 Vogel - 123 |
Seh ich das richtig?
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 12:01
ja, aber man solle sauch nach anderen spalten sortieren können...
Und bei deinem Script wird nur die angeklickte spalte sortiert...
also aus
Quelltext 1: 2: 3: 4:
| a b c 1 3 2 2 2 1 3 1 3 |
wird, wenn man nach "b" sortiert bei dir nur:
Quelltext 1: 2: 3: 4:
| a b c 1 1 2 2 2 1 3 3 3 |
es muss aber:
Quelltext 1: 2: 3: 4:
| a b c 3 1 3 2 2 1 1 3 2 |
werden, in jeder zeile gehören die 3 werte zusammen, und müssen auch zusammen verschoben werden...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
ZeitGeist87
Beiträge: 1593
Erhaltene Danke: 20
Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
|
Verfasst: Di 08.07.08 12:03
Soweit hab ich dein Problem dann doch verstanden
Ich denk mal beim Mittagessen nach..in ner halben Stunde..
_________________ Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 12:08
okay, ich ess jetzt grade mein brötchen... aber ist schon ok...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Di 08.07.08 12:35
hab die lösung:
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| function sortTable(column, order){ for(var i = 1; i < document.getElementById("GridView1").getElementsByTagName("tr").length-1; i++){ for(var j = i; j < document.getElementById("GridView1").getElementsByTagName("tr").length; j++){ if(i != j){ if(order == "asc"){ if(document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[column].innerHTML > document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[column].innerHTML){ var buffer = Array(); for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.length; k++){ buffer[k] = document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k].innerHTML; document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k].innerHTML = document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k].innerHTML; document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k].innerHTML = buffer[k]; } } }else{ if(document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[column].innerHTML < document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[column].innerHTML){ var buffer = Array(); for(var k = 0; k < document.getElementById("GridView1").getElementsByTagName("tr")[i].cells.length; k++){ buffer[k] = document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k].innerHTML; document.getElementById("GridView1").getElementsByTagName("tr")[i].cells[k].innerHTML = document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k].innerHTML; document.getElementById("GridView1").getElementsByTagName("tr")[j].cells[k].innerHTML = buffer[k]; } } } } } } } |
Wenn es sein muss, dann muss man man jede einzelne zelle mit der der anderen reihe vertauschen...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|