920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
|
return rc;
}
/*
** Output Javascript code that will enables sorting of the table with
** the id zTableId by clicking.
**
** The javascript is derived from:
**
** http://www.webtoolkit.info/sortable-html-table.html
**
** This variation allows column types to be expressed using the second
** argument. Each character of the second argument represent a column.
**
** t Sort by text
** n Sort numerically
** k Sort by the data-sortkey property
** x This column is not sortable
**
** If there are fewer characters in zColumnTypes[] than their are columns,
** the all extra columns assume type "t" (text).
**
** Clicking on the same column header twice in a row inverts the sort.
*/
void output_table_sorting_javascript(const char *zTableId, const char *zColumnTypes){
@ <script>
@ function SortableTable(tableEl,columnTypes){
@ this.tbody = tableEl.getElementsByTagName('tbody');
@ this.sort = function (cell) {
@ var column = cell.cellIndex;
@ var sortFn;
@ switch( cell.sortType ){
@ case "n": sortFn = this.sortNumeric; break;
@ case "t": sortFn = this.sortText; break;
@ case "k": sortFn = this.sortKey; break;
@ case "x": return;
@ }
@ this.sortIndex = column;
@ var newRows = new Array();
@ for (j = 0; j < this.tbody[0].rows.length; j++) {
@ newRows[j] = this.tbody[0].rows[j];
@ }
@ if( this.sortIndex==this.prevColumn ){
@ newRows.reverse();
@ }else{
@ newRows.sort(sortFn);
@ this.prevColumn = this.sortIndex;
@ }
@ for (i=0;i<newRows.length;i++) {
@ this.tbody[0].appendChild(newRows[i]);
@ }
@ }
@ this.sortText = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ if(aa==bb) return 0;
@ if(aa<bb) return -1;
|
|
>
>
>
>
>
>
>
|
>
>
>
>
|
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
|
return rc;
}
/*
** Output Javascript code that will enables sorting of the table with
** the id zTableId by clicking.
**
** The javascript was originally derived from:
**
** http://www.webtoolkit.info/sortable-html-table.html
**
** But there have been extensive modifications.
**
** This variation allows column types to be expressed using the second
** argument. Each character of the second argument represent a column.
**
** t Sort by text
** n Sort numerically
** k Sort by the data-sortkey property
** x This column is not sortable
**
** If there are fewer characters in zColumnTypes[] than their are columns,
** the all extra columns assume type "t" (text).
**
** The third parameter is the column that was initially sorted (using 1-based
** column numbers, like SQL). Make this value 0 if none of the columns are
** initially sorted. Make the value negative if the column is initially sorted
** in reverse order.
**
** Clicking on the same column header twice in a row inverts the sort.
*/
void output_table_sorting_javascript(
const char *zTableId, /* ID of table to sort */
const char *zColumnTypes, /* String for column types */
int iInitSort /* Initially sorted column. Leftmost is 1. 0 for NONE */
){
@ <script>
@ function SortableTable(tableEl,columnTypes,initSort){
@ this.tbody = tableEl.getElementsByTagName('tbody');
@ this.columnTypes = columnTypes;
@ this.sort = function (cell) {
@ var column = cell.cellIndex;
@ var sortFn;
@ switch( cell.sortType ){
@ case "n": sortFn = this.sortNumeric; break;
@ case "t": sortFn = this.sortText; break;
@ case "k": sortFn = this.sortKey; break;
@ case "x": return;
@ }
@ this.sortIndex = column;
@ var newRows = new Array();
@ for (j = 0; j < this.tbody[0].rows.length; j++) {
@ newRows[j] = this.tbody[0].rows[j];
@ }
@ if( this.sortIndex==Math.abs(this.prevColumn)-1 ){
@ newRows.reverse();
@ this.prevColumn = -this.prevColumn;
@ }else{
@ newRows.sort(sortFn);
@ this.prevColumn = this.sortIndex+1;
@ }
@ for (i=0;i<newRows.length;i++) {
@ this.tbody[0].appendChild(newRows[i]);
@ }
@ this.setHdrIcons();
@ }
@ this.setHdrIcons = function() {
@ var arrowdiv = this.hdrRow.getElementsByClassName("sortarrow");
@ while( arrowdiv[0] ){
@ arrowdiv[0].parentNode.removeChild(arrowdiv[0]);
@ }
@ for (var i=0; i<this.hdrRow.cells.length; i++) {
@ if( this.columnTypes[i]=='x' ) continue;
@ if( this.prevColumn==i+1 ){
@ arrow = "\u2b07";
@ }else if( this.prevColumn==(-1-i) ){
@ arrow = "\u2b06";
@ }else{
@ arrow = "\u21f3";
@ }
@ this.hdrRow.cells[i].innerHTML +=
@ "<span class='sortarrow'>" + arrow + "</div>";
@ }
@ }
@ this.sortText = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ if(aa==bb) return 0;
@ if(aa<bb) return -1;
|
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
|
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].getAttribute("data-sortkey");
@ bb = b.cells[i].getAttribute("data-sortkey");
@ if(aa==bb) return 0;
@ if(aa<bb) return -1;
@ return 1;
@ }
@ var thisObject = this;
@ var prevColumn = -1;
@ var x = tableEl.getElementsByTagName('thead');
@ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
@ return;
@ }
@ if(x && x[0].rows && x[0].rows.length > 0) {
@ var sortRow = x[0].rows[0];
@ } else {
@ return;
@ }
@ for (var i=0; i<sortRow.cells.length; i++) {
@ if( columnTypes[i]=='x' ) continue;
@ sortRow.cells[i].sTable = this;
@ sortRow.cells[i].style.cursor = "pointer";
@ sortRow.cells[i].sortType = columnTypes[i] || 't';
@ sortRow.cells[i].onclick = function () {
@ this.sTable.sort(this);
@ return false;
@ }
@ }
@ }
@ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)");
@ </script>
}
/*
** WEBPAGE: /rptview
**
|
<
<
|
>
>
|
>
|
|
|
|
>
|
|
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
|
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].getAttribute("data-sortkey");
@ bb = b.cells[i].getAttribute("data-sortkey");
@ if(aa==bb) return 0;
@ if(aa<bb) return -1;
@ return 1;
@ }
@ var x = tableEl.getElementsByTagName('thead');
@ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
@ return;
@ }
@ if(x && x[0].rows && x[0].rows.length > 0) {
@ this.hdrRow = x[0].rows[0];
@ } else {
@ return;
@ }
@ var thisObject = this;
@ this.prevColumn = initSort;
@ for (var i=0; i<this.hdrRow.cells.length; i++) {
@ if( columnTypes[i]=='x' ) continue;
@ var hdrcell = this.hdrRow.cells[i];
@ hdrcell.sTable = this;
@ hdrcell.style.cursor = "pointer";
@ hdrcell.sortType = columnTypes[i] || 't';
@ hdrcell.onclick = function () {
@ this.sTable.sort(this);
@ return false;
@ }
@ }
@ this.setHdrIcons()
@ }
@ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)",%d(iInitSort));
@ </script>
}
/*
** WEBPAGE: /rptview
**
|
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
|
report_unrestrict_sql();
@ </tbody></table>
if( zErr1 ){
@ <p class="reportError">Error: %h(zErr1)</p>
}else if( zErr2 ){
@ <p class="reportError">Error: %h(zErr2)</p>
}
output_table_sorting_javascript("reportTable","");
style_footer();
}else{
report_restrict_sql(&zErr1);
db_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
report_unrestrict_sql();
cgi_set_content_type("text/plain");
}
|
|
|
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
|
report_unrestrict_sql();
@ </tbody></table>
if( zErr1 ){
@ <p class="reportError">Error: %h(zErr1)</p>
}else if( zErr2 ){
@ <p class="reportError">Error: %h(zErr2)</p>
}
output_table_sorting_javascript("reportTable","",0);
style_footer();
}else{
report_restrict_sql(&zErr1);
db_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
report_unrestrict_sql();
cgi_set_content_type("text/plain");
}
|