home *** CD-ROM | disk | FTP | other *** search
- function ZotrTable(id,rows,cols,border,width,align) {
- this.id = id
- this.rows = rows
- this.cols = cols
- this.border = border
- this.width = width
- this.align = align
- this.buttons = new Array(cols)
- this.numeric = new Array(cols)
- for(var i=0;i<cols;++i)
- this.buttons[i]=" "
- for(var i=0;i<cols;++i)
- this.numeric[i]=false
- this.data = new Array(rows)
- for(var i=0;i<rows;++i) {
- this.data[i] = new Array(cols)
- for(var j=0;j<cols;++j)
- this.data[i][j] = " "
- }
- this.display = ZotrTable_display
- this.setButtons = ZotrTable_setButtons
- this.setData = ZotrTable_setData
- this.setNumeric = ZotrTable_setNumeric
- this.sort = ZotrTable_sort
- }
- function ZotrTable_setData(data) {
- if(data == null) return
- if(data.length > 0) {
- for(var i=0;i<this.rows;++i) {
- if(i>=data.length) break
- if(data[i] != null) {
- var n = data[i].length
- if(n > this.cols) n = this.cols
- for(var j=0;j<n;++j)
- if(data[i][j]!=null) this.data[i][j] = data[i][j]
- }
- }
- }
- }
- function ZotrTable_setButtons(buttons) {
- if(buttons == null) return
- var n = buttons.length
- if(n > this.cols) n = this.cols
- for(var i=0;i<n;++i)
- if(buttons[i]!=null) this.buttons[i] = buttons[i]
- }
- function ZotrTable_display() {
- //cookie
- if(document.cookie.length > 0) {
- var search = this.id + "="
- var offset = document.cookie.indexOf(this.id+"=")
- if(offset != -1) {
- offset += search.length
- var end = document.cookie.indexOf(";", offset)
- if(end == -1) end = document.cookie.length
- this.sort(document.cookie.substring(offset, end))
- }
- }
- document.writeln('<FORM NAME="tableForm">')
- document.write('<TABLE BORDER="'+this.border+'" WIDTH="')
- document.writeln(this.width+'" ALIGN="'+this.align+'">')
- document.writeln('<TR>')
- // Zobraz buttons
- for(var i=0;i<this.cols;++i) {
- document.write('<TD>')
- document.write('<INPUT TYPE="BUTTON" VALUE="')
- document.write(this.buttons[i])
- document.write('" ONCLICK="ZotrTable_handleColumnButton(\'')
- document.write(this.id+'\','+i+')">')
- document.writeln('</TD>')
- }
- document.writeln('</TR>')
- // Zobraz zotriedene/nezotriedene udaje v tabulke
- for(var i=0;i<this.rows;++i) {
- document.writeln('<TR>')
- for(var j=0;j<this.cols;++j) {
- document.write('<TD>')
- document.write(this.data[i][j])
- document.writeln('</TD>')
- }
- document.writeln('</TR>')
- }
- document.writeln('</TABLE>')
- document.writeln('</FORM>')
- }
- function ZotrTable_setNumeric(n) {
- this.numeric[n] = true
- }
- function ZotrTable_sort(n) {
- // Sort rows
- var changes=true
- for(;changes;) {
- changes = false
- for(var i=0;i<this.rows-1;++i) {
- if(this.numeric[n]) {
- var v1 = parseFloat(this.data[i][n])
- if(isNaN(v1)) v1 = 0;
- var v2 = parseFloat(this.data[i+1][n])
- if(isNaN(v2)) v2 = 0;
- if(v1 > v2) {
- changes = true
- var temp = this.data[i]
- this.data[i] = this.data[i+1]
- this.data[i+1] = temp
- }
- }else{
- if(this.data[i][n] > this.data[i+1][n]) {
- changes = true
- var temp = this.data[i]
- this.data[i] = this.data[i+1]
- this.data[i+1] = temp
- }
- }
- }
- }
- }
- function ZotrTable_handleColumnButton(id,n) {
- //cookie a reload
- document.cookie = id + "="+n
- window.location.reload()
- }
-