How to create a table with first column fixed using HTML/CSS? - html

I want to create a table which can be scrolled horizontally. The number of columns is dynamic. I want to achieve when we scroll the table horizontally the first column needs to be fixed/frozen. I have tried the following css. The first column is fixed alright but, second, third columns are hidden under the fixed column.
.mydiv {
overflow-y: scroll;
}.headcol {
position:absolute;
width: 100px;
text-align:center;
background-color: #4CAF50;
color: white;
font-family:arial;
font-size:13px;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
border: 1px solid #c4c0c0;
}
.tablemy {
border-collapse: collapse;
border: 1px solid #c4c0c0;
}
.thmy {
text-align:center;
background-color: #4CAF50;
color: white;
font-family:arial;
font-size:13px;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
border: 1px solid #c4c0c0;
}
.tdmy {
white-space: nowrap;
padding:8px; border-left:1px solid #ccc; border-top:1px solid #ccc;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
font-size:12px;
font-family:arial;
border: 1px solid #c4c0c0;
color:#585858;
}
.trmy:nth-child(odd) {
background-color:#F5F5F5;
}
tr:nth-child(even) {
background-color:#ffffff;
}
And my table is
I'm creating my table in javascript.
$(window).load(function(){
var customers = new Array();
customers.push(["TN04 AH 0253", "55"]);
customers.push(["TN04 AF 8830", "67"]);
customers.push(["TN37 CM 1249", "33"]);
customers.push(["TN19 F 9175", "47"]);
customers.push(["TN37CM 1932", "0"]);
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var dateArray = getDates(firstDay, lastDay);
// Create a HTML Table element.
var table = document.createElement("TABLE");
table.setAttribute('class', 'tablemy');
table.border = "1";
// Get the count of columns.
var columnCount = customers[0].length;
var row = table.insertRow(-1);
for (var i = 0; i < dateArray.length; i++) {
var headerCell = document.createElement("TH");
if (i === 0) {
headerCell.setAttribute('class', 'headcol');
} else {
headerCell.setAttribute('class', 'thmy');
}
//headerCell.setAttribute('class', 'thmy');
headerCell.innerHTML = dateArray[i];
row.appendChild(headerCell);
}
// Add the data rows.
for (var i = 0; i < customers.length; i++) {
row = table.insertRow(-1);
row.setAttribute('class', 'trmy');
for (var j = 0; j < columnCount; j++) {
var cell = row.insertCell(-1);
if (j === 0) {
cell.setAttribute('class', 'headcol');
} else {
cell.setAttribute('class', 'tdmy');
}
//cell.setAttribute('class', 'tdmy');
cell.innerHTML = customers[i][j];
}
}
var dvTable = document.getElementById("dvTable");
dvTable.innerHTML = "";
dvTable.appendChild(table);
})
function getDates(date1, date2) {
var day = 1000 * 60 * 60 * 24;
var diff = (date2.getTime() - date1.getTime())/day;
var dateArray = new Array();
dateArray.push("Unit/Count");
for(var i=0; i<=diff; i++)
{
var xx = date1.getTime() + day * i;
var yy = new Date(xx);
var strDate = yy.getDate() + "/" + (yy.getMonth() + 1);
dateArray.push(strDate);
}
return dateArray;
}

I think you need to set position: fixed for 1st column and to make all other columns visible you need to set padding-left: 130px; (which is equal to width of first column) for .tablemy :
function getDates(date1, date2) {
var day = 1000 * 60 * 60 * 24;
var diff = (date2.getTime() - date1.getTime())/day;
var dateArray = new Array();
dateArray.push("Unit/Count");
for(var i=0; i<=diff; i++)
{
var xx = date1.getTime() + day * i;
var yy = new Date(xx);
var strDate = yy.getDate() + "/" + (yy.getMonth() + 1);
dateArray.push(strDate);
}
return dateArray;
}
var customers = new Array();
customers.push(["TN04 AH 0253", "55"]);
customers.push(["TN04 AF 8830", "67"]);
customers.push(["TN37 CM 1249", "33"]);
customers.push(["TN19 F 9175", "47"]);
customers.push(["TN37CM 1932", "0"]);
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var dateArray = getDates(firstDay, lastDay);
// Create a HTML Table element.
var table = document.createElement("TABLE");
table.setAttribute('class', 'tablemy');
table.border = "1";
// Get the count of columns.
var columnCount = customers[0].length;
var row = table.insertRow(-1);
for (var i = 0; i < dateArray.length; i++) {
var headerCell = document.createElement("TH");
if (i === 0) {
headerCell.setAttribute('class', 'headcol');
} else {
headerCell.setAttribute('class', 'thmy');
}
//headerCell.setAttribute('class', 'thmy');
headerCell.innerHTML = dateArray[i];
row.appendChild(headerCell);
}
// Add the data rows.
for (var i = 0; i < customers.length; i++) {
row = table.insertRow(-1);
row.setAttribute('class', 'trmy');
for (var j = 0; j < columnCount; j++) {
var cell = row.insertCell(-1);
if (j === 0) {
cell.setAttribute('class', 'headcol');
} else {
cell.setAttribute('class', 'tdmy');
}
//cell.setAttribute('class', 'tdmy');
cell.innerHTML = customers[i][j];
}
}
var dvTable = document.getElementById("dvTable");
dvTable.innerHTML = "";
dvTable.appendChild(table);
html, body {
margin: 0;
padding: 0;
}
.mydiv {
overflow-y: scroll;
}
.headcol {
position: fixed;
left: 0;
width: 100px;
text-align:center;
background-color: #4CAF50;
color: white;
font-family:arial;
font-size:13px;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
border: 1px solid #c4c0c0;
}
.tablemy {
border-collapse: collapse;
border: 1px solid #c4c0c0;
margin-left: 130px;
}
.thmy {
text-align:center;
background-color: #4CAF50;
color: white;
font-family:arial;
font-size:13px;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
border: 1px solid #c4c0c0;
}
.tdmy {
white-space: nowrap;
padding:8px; border-left:1px solid #ccc; border-top:1px solid #ccc;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
font-size:12px;
font-family:arial;
border: 1px solid #c4c0c0;
color:#585858;
}
.trmy:nth-child(odd) {
background-color:#F5F5F5;
}
tr:nth-child(even) {
background-color:#ffffff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="dvTable"></table>

Related

How to have a non-rectangular div?

With HTML/CSS, how to create a non-rectangular red container like this:
which is basically a "rectangle avoiding a top right rectangle":
Is there another solution than having float: right; for the top right blue container?
Reason: I'm looking for other methods than float: right because of an Electron bug that prevent clicks to be caught correctly on the top right blue container, when the red container is a "draggable" title bar for an app window.
The following snippet works perfectly, but I'm looking for another solution without float: right:
for (var i = 0; i < 50; i++)
document.getElementById("topleft").innerHTML += "<button>xyz" + i + "</button>";
* { margin: 0; }
#topright { float: right; width: 100px; background-color: blue; -webkit-app-region: no-drag; }
#topright:hover { background-color: black; }
#topleft { background-color: red; -webkit-app-region: drag; padding: 10px; }
<div id="topright" onclick="alert();">Click here!</div>
<div id="topleft"></div>
finally! it took a little doing but I believe this should do it.
function myFunction2(){
alert('i was clicked')
}
function myFunction(){
for (let i = 0; i < 50; i++){
let x = 'a0' + i
let id = 'a' + (x).slice(-2)
document.getElementById(id).innerHTML = 'xyz' +i;
}
var end = 0;
var count = 0;
var left =[];
for (let i = 0; i < 25;i++){
let y = 30 + i*20;
let temp = document.elementFromPoint(18, y);
if (document.elementFromPoint(18, y)==null)return;
if (temp.tagName != 'SPAN')break;
let inner = temp.innerHTML;
let inArray = inner.split('z')
var start = parseInt(inArray[1]);
left.push(start)
}
left[left.length-1] = 50
for (var i = 0;i < left.length;i++){
for(let j = left[i]; j >= end; j--){
let x = 'a0' + j
let id = 'a' + (x).slice(-2)
if (document.getElementById(id) != null)
document.getElementById(id).innerHTML = 'xyz' + count;
count++;
}
end = left[i]+1
}
} window.addEventListener('resize', myFunction);
div{
margin:0;padding:0;
}
#better{
margin-top:20px;
display:block;
background:green;
width:100%;
position:relative;
padding:10px;
}
#abs{
display:inline-flex;
justify-content:center;
position:absolute;
background:blue;
height:30px;
width:100px;
top:0%;
right:0%;
}
span{
background:white;
border:solid 1px grey;
display:inline-block;
font-size:16px;
}
#fx{
display:flex;
flex-flow: row-reverse wrap;
justify-content:flex-end;
}
#x{
width:100px;
visibility:hidden;
}
<html>
<body >
<div id='better' >
<div id='fx'>
<span id='x'></span>
<span id='a00'>xyz0</span><span id='a01'>xyz1</span><span id='a02'>xyz2</span><span id='a03'>xyz3</span><span id='a04'>xyz4</span><span id='a05'>xyz5</span><span id='a06'>xyz6</span><span id='a07'>xyz7</span><span id='a08'>xyz8</span><span id='a09'>xyz9</span><span id='a10'>xyz10</span><span id='a11'>xyz11</span>
<span id='a12'>xyz12</span><span id='a13'>xyz13</span><span id='a14'>xyz14</span><span id='a15'>xyz15</span><span id='a16'>xyz16</span><span id='a17'>xyz17</span><span id='a18'>xyz18</span><span id='a19'>xyz19</span><span id='a20'>xyz20</span><span id='a21'>xyz21</span><span id='a22'>xyz22</span><span id='a23'>xyz23</span>
<span id='a24'>xyz24</span><span id='a25'>xyz25</span><span id='a26'>xyz26</span><span id='a27'>xyz27</span><span id='a28'>xyz28</span><span id='a29'>xyz29</span><span id='a30'>xyz30</span><span id='a31'>xyz31</span><span id='a32'>xyz32</span><span id='a33'>xyz33</span><span id='a34'>xyz34</span><span id='a35'>xyz35</span>
<span id='a36'>xyz36</span><span id='a37'>xyz37</span><span id='a38'>xyz38</span><span id='a39'>xyz39</span><span id='a40'>xyz40</span><span id='a41'>xyz41</span><span id='a42'>xyz42</span><span id='a43'>xyz43</span><span id='a44'>xyz44</span><span id='a45'>xyz45</span><span id='a46'>xyz46</span><span id='a47'>xyz47</span>
<span id='a48'>xyz48</span><span id='a49'>xyz49</span><span id='a50'>xyz50</span>
</div>
<div id='abs'>
<button type='button' onclick='myFunction2()'>Click me!</button>
</div>
</div>
</body>
</html>

Stop div from resizing past its parent <td>

.date td div{
width: 100%;
height: 100%;
box-sizing: border-box;
white-space: nowrap;
word-wrap: ellipsis;
overflow:auto;
}
Codepen: http://codepen.io/Intelli/pen/qRYyxa
I have tried every variation of width, height, box-sizing, white-space and word-wrap and nothing seems to work. All I need is if the text is horizontally too long, then add a break, if it's vertically too long, add a scroll bar.
Use table-layout: fixed; to keep the table elements from growing past the defined dimensions, and remove white-space: nowrap; from the nested div so the text will wrap if it's too wide. http://codepen.io/mcoker/pen/WRWLxV
var Calendar = function(){
this.day;
this.month;
this.date;
this.year;
this.events = [];
}
var Event = function(){
this.title;
this.location;
this.id;
this.start_time;
this.end_time;
this.start_month;
this.start_day;
this.start_date;
this.start_year;
this.end_month;
this.end_day;
this.end_date;
this.end_year;
this.email;
this.phone;
this.description;
};
var calendarMonth = [];
var days = ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var startDay;
var startMonth;
var startDate;
var startYear;
/**Create a calendar*/
function getCalendar(cal) {
$(".month h2").text(months[cal.month]);
$(".month h3").text(cal.year);
$(".calendar tr").eq(2).find("td").eq(2).find("div").html("This is a very long test string to see if the div resizes past the td width </br> I also dont want to use overflow:hidden because I want a (VERTICAL ONLY)scroll bar if the height of the text is too long </br> Testing scroll </br> Testing scroll </br> Testing scroll </br> Testing scroll </br> Testing scroll </br> Testing scroll </br> Testing scroll");
var daysInMonth = getDaysInMonth(months[cal.month], cal.year);
startDay = cal.day;
startDate = cal.date;
startMonth = cal.month;
startYear = cal.year;
/**row 2 because that is the one with the dates*/
var row = 2;
if (cal.day != 0){
for (var j = cal.day - 1; j >= 0; j--) {
$(".calendar tr").eq(row).find("td").eq(j).find("div").css("background-color", "#b1c9ce");
}
}
/**fill the calendar appropriately*/
while (cal.date <= daysInMonth) {
if (cal.day == days.length) {
row++;
cal.day = 0;
$(".calendar").append('<tr class="date"><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td></tr>');
}
$(".calendar tr").eq(row).find("td").eq(cal.day).find("div").text(cal.date);
var temp = new Calendar();
temp.day = cal.day;
temp.month = cal.month;
temp.date = cal.date;
temp.year = cal.year;
temp.events.push(new Event());
calendarMonth.push(temp);
cal.day++;
cal.date++;
}
lastDay = cal.day;
cal.date = 1;
var j = cal.day;
if (cal.day <= 6) {
for (j = cal.day; j < days.length; j++) {
$(".calendar tr").eq(row).find("td").eq(j).find("div").css("background-color", "#b1c9ce");
}
}
while (cal.day < days.length) {
$(".calendar tr").eq(row).find("td").eq(cal.day).find("div").text(cal.date);
cal.day++;
cal.date++;
}
}
function getDaysInMonth(startMonth, startYear) {
var daysInMonth;
/**Get the number of days in the month given*/
if ((startMonth == "January") || (startMonth == "March") || (startMonth == "May") || (startMonth == "July") || (startMonth == "August") || (startMonth == "October") || (startMonth == "December")) {
daysInMonth = 31;
} else if ((startMonth == "April") || (startMonth == "June") || (startMonth == "September") || (startMonth == "November")) {
daysInMonth = 30;
} else if (startMonth == "February") {
if (startYear % 4 == 0) {
daysInMonth = 29;
} else {
daysInMonth = 28;
}
}
return daysInMonth;
}
$(function() {
var calendar = new Calendar();
var d = new Date();
var firstDay = new Date(d.getFullYear(), d.getMonth(), 1);
calendar.day = firstDay.getDay();
calendar.month = firstDay.getMonth();
calendar.year = firstDay.getFullYear();
calendar.date = firstDay.getDate();
getCalendar(calendar);
$(".Prev").click(function() {
calendarMonth = [];
var temp = new Calendar();
if(startMonth == 0){
startMonth = 11;
startYear--;
}
else startMonth--;
var daysInMonth = getDaysInMonth(months[startMonth], startYear);
var index = startDay - (daysInMonth % 7);
if(index < 0) index += 7;
startDay = index;
temp.day = startDay;
temp.date = startDate;
temp.month = startMonth;
temp.year = startYear;
$(".date").remove();
$(".calendar").append('<tr class="date"><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td></tr>');
getCalendar(temp);
});
$(".Next").click(function() {
calendarMonth = [];
var temp = new Calendar();
var daysInMonth = getDaysInMonth(months[startMonth], startYear);
if (startMonth == 11) {
startYear++;
startMonth = 0;
} else {
startMonth++;
}
var index = startDay + (daysInMonth % 7);
if(index > 6) index = 7 - index;
if(index < 0) index *= -1;
startDay = index;
temp.day = startDay;
temp.date = startDate;
temp.month = startMonth;
temp.year = startYear;
$(".date").remove();
$(".calendar").append('<tr class="date"><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td><td><div></div></td></tr>');
getCalendar(temp);
});
});
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
border: 2px solid darkgray;
color: #d9d9d9;
/**Month/Year text color*/
table-layout: fixed;
}
td,
th {
text-align: left;
max-width: 14.28%;
border: 2.5px solid darkgray;
background-color: #DFE9EB;
/**cell background-color*/
}
td {
color: black;
}
tr:nth-child(even) {
background-color: #dddddd;
}
.calendar {
margin-right: auto;
margin-left: auto;
/*width: 75%;*/
height: 100%;
}
.month {
height: 5%;
background-color: #2c7b87;
/**Month/Year background color*/
border: none;
border-bottom: #c20a38 solid 1.5vh;
}
.month h2 {
height: 30%;
color: #d9d9d9;
text-align: center;
}
.month h3 {
height: 30%;
color: #d9d9d9;
text-align: center;
}
.date td {
text-align: left;
vertical-align: top;
font-size: 1.5vh;
height: 10vh;
}
.date td div {
width: 100%;
height: 100%;
box-sizing: border-box;
word-wrap: ellipsis;
overflow: auto;
}
.day th {
color: #595959;
colspan="1";
width: 30vh;
text-align: center;
}
.Prev,
.Next {
width: 30%;
height: 30%;
font-size: 20px;
display: block;
margin: auto;
}
<table class="calendar">
<tr>
<td class="month"><button class="Prev"><</button></td>
<td class="month"></td>
<td class="month"></td>
<td class="month"><h2>Month<h3>Year</h3></h2></td>
<td class="month"></td>
<td class="month"></td>
<td class="month"><button class="Next">></button></td>
</tr>
<tr class="day">
<th>
<h3>Sunday</h3></th>
<th>
<h3>Monday</h3></th>
<th>
<h3>Tuesday</h3></th>
<th>
<h3>Wednesday</h3></th>
<th>
<h3>Thursday</h3></th>
<th>
<h3>Friday</h3></th>
<th>
<h3>Saturday</h3></th>
</tr>
<tr class="date">
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
<td><div></div></td>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

HTML fixed header in table dynamically in ASP.NET

I created a table dynamically, being populated from database. What want to do is to created a fixed header and a scrollable body. I tried css and javascript but didn't manage to do anything, I think because table is created automatically.
Help.
Here is my code:
private void GenerateTable();
{
DataTable dt = CreateDataTable();//in CreateDataTable I just take all my reocrds from database
Table table = new Table();
TableRow row = null;
row = new TableRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = dt.Columns[j].ColumnName;
row.Cells.Add(headerCell);
}
table.Rows.Add(row);
//Add the Column values
for (int i = 0; i < dt.Rows.Count; i++)
{
row = new TableRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
TableCell cell = new TableCell();
cell.Text = dt.Rows[i][j].ToString();
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
tablediv.Controls.Add(table);
}
Div where I add the table:
<div class="mainEntry" style="width:90%" id="tablediv" runat="server" />
And my CSS for table:
table {
border-collapse: collapse;
width: 100%;
color: white;
}
th, td {
text-align: left;
padding: 8px;
}
th{
font-size:20px;
}
tbody{
height:500px;
overflow:auto;
display:block;
}
tr:nth-child(even){background-color: rgba(255, 255, 255, .15)}
th {
background-color: rgba(174, 183, 212, .15);
color: white;
}
I hope this css classes demo can help you. Visit fiddlehttp://jsfiddle.net/TweNm/

Fix div position with respect to another div when zoom

I have the following HTML. The problem is that I can not make the div with id="ladder" have the same position with respect to its parent div with id="grid" when I zoom in or out. here is the code snakes and Ladders
var gameBoard = {
createBoard: function(dimension, mount) {
var mount = document.querySelector(mount);
if (!dimension || isNaN(dimension) || !parseInt(dimension, 10)) {
return false;
} else {
dimension = typeof dimension === 'string' ? parseInt(dimension, 10) : dimension;
var table = document.createElement('table'),
row = document.createElement('tr'),
cell = document.createElement('td'),
rowClone,
cellClone;
var output;
for (var r = 0; r < dimension; r++) {
rowClone = row.cloneNode(true);
table.appendChild(rowClone);
for (var c = 0; c < dimension; c++) {
cellClone = cell.cloneNode(true);
rowClone.appendChild(cellClone);
}
}
mount.appendChild(table);
output = gameBoard.enumerateBoard(table);
}
return output;
},
enumerateBoard: function(board) {
var rows = board.getElementsByTagName('tr'),
text = document.createTextNode(''),
rowCounter = 1,
size = rows.length,
cells,
cellsLength,
cellNumber,
odd = false,
control = 0;
for (var r = size - 1; r >= 0; r--) {
cells = rows[r].getElementsByTagName('td');
cellsLength = cells.length;
rows[r].className = r % 2 == 0 ? 'even' : 'odd';
odd = ++control % 2 == 0 ? true : false;
size = rows.length;
for (var i = 0; i < cellsLength; i++) {
if (odd == true) {
cellNumber = --size + rowCounter - i;
} else {
cellNumber = rowCounter;
}
cells[i].className = i % 2 == 0 ? 'even' : 'odd';
cells[i].id = cellNumber;
cells[i].appendChild(text.cloneNode());
cells[i].firstChild.nodeValue = cellNumber;
rowCounter++;
}
}
var lastRow = rows[0].getElementsByTagName('td');
lastRow[0].id = '100';
var firstRow = rows[9].getElementsByTagName('td');
firstRow[0].id = '1';
return gameBoard;
}
};
gameBoard.createBoard(10, "#grid");
function intialPosition() {
$("#1").append($("#player1"));
$("#1").append($("#player2"));
var currentPosition = parseInt($("#1").attr('id'));
return currentPosition;
}
var start = intialPosition();
var face1 = new Image();
face1.src = "http://s19.postimg.org/fa5etrfy7/image.gif";
var face2 = new Image();
face2.src = "http://s19.postimg.org/qb0jys873/image.gif";
var face3 = new Image();
face3.src = "http://s19.postimg.org/fpgoms1vj/image.gif";
var face4 = new Image();
face4.src = "http://s19.postimg.org/xgsb18ha7/image.gif";
var face5 = new Image();
face5.src = "http://s19.postimg.org/lsy96os5b/image.gif";
var face6 = new Image();
face6.src = "http://s19.postimg.org/4gxwl8ynz/image.gif";
function rollDice() {
var status = document.getElementById("status");
var random = Math.floor(Math.random() * 6) + 1;
document.images["mydice"].src = eval("face" + random + ".src")
status.innerHTML = "You rolled " + random;
//if (random == 6) {
// status.innerHTML += "! You get a free turn!!";
//}
return random;
}
var currentPosition = start;
var random1;
function move() {
var m = 1;
random1 = rollDice();
destination = currentPosition + random1;
$('#' + destination).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
$('#' + destination).append($('#player' + m));
if (destination == 36) {
destination = 55;
$('#' + destination).append($('#' + "player" + m));
}
if (destination == 96) {
destination = 57;
$('#' + destination).append($('#' + "player" + m));
}
if (destination >= 100) {
destination = 100;
$('#' + destination).append($('#' + "player" + m));
alert("You Won!!!!!!!");
}
currentPosition = parseInt($('#' + destination).attr('id'));
return currentPosition;
}
/*body {
background-image: url('snakesandladder2.png');
background-repeat: no-repeat;
background-size: 100%;
background-color: #4f96cb;
}*/
#game {
width: 80%;
margin-left: auto;
margin-right: auto;
display: table;
}
#gameBoardSection {
border: 3px inset #0FF;
border-radius: 10px;
width: 65%;
display: table-cell;
position: relative;
/*margin: 5px;*/
/*margin: auto;*/
}
/*#grid{
position:relative;
}*/
table {
width: 100%;
position: relative;
}
td {
border-radius: 10px;
width: 60px;
height: 60px;
line-height: normal;
vertical-align: bottom;
text-align: left;
border: 0px solid #FFFFFF;
position: relative;
}
table tr:nth-child(odd) td:nth-child(even),
table tr:nth-child(even) td:nth-child(odd) {
/*color: #FF0000 ;*/
background-color: PowderBlue;
}
table tr:nth-child(even) td:nth-child(even),
table tr:nth-child(odd) td:nth-child(odd) {
background-color: SkyBlue;
}
#100 {
background-image: url('rotstar2_e0.gif');
background-repeat: no-repeat;
background-size: 100%;
}
#ladder {
position: absolute;
top: 300px;
left: 470px;
-webkit-transform: rotate(30deg);
z-index: 1;
opacity: 0.7;
}
#bigSnake {
position: absolute;
top: 20px;
left: 200px;
opacity: 0.7;
z-index: 1;
}
#playerAndDiceSection {
background-color: lightpink;
border: 1px;
border-style: solid;
display: table-cell;
/*margin: 2px;*/
border-radius: 10px;
border: 3px inset #0FF;
width: 35%;
margin: 2%;
}
<body>
<div id="game">
<div id="gameBoardSection">
<div id="grid"></div>
<div id="ladder">
<img src="http://s19.postimg.org/otai9he2n/oie_e_RDOY2iqd5o_Q.gif" />
</div>
<div id="bigSnake">
<img src="http://s19.postimg.org/hrcknaagz/oie_485727s_RN4_KKBG.png" />
</div>
<div id="player1" style="position:absolute; top:10px; left:10px;">
<!--style="position: absolute; top: 597px; z-index: 1;"-->
<img src="http://s19.postimg.org/t108l496n/human_Piece.png" />
</div>
<div id="player2" style="position:absolute; top:15px; left:5px;">
<img src="http://s19.postimg.org/l6zmzq1dr/computer_Piece.png" />
</div>
</div>
<div id="playerAndDiceSection">
<div id="playerSection">
<div id="player1">
<img src="http://s19.postimg.org/t108l496n/human_Piece.png" />Player1
<!--<p>Player1</p>-->
</div>
<div id="player2">
<img src="http://s19.postimg.org/l6zmzq1dr/computer_Piece.png" />Player2
</div>
</div>
<div id="diceSection">
<img src="http://s19.postimg.org/fa5etrfy7/image.gif" name="mydice" onclick="move()" style="background-color: white;">
<h2 id="status"></h2>
</div>
</div>
</div>
</body>

How to convert excel(xls) file to html and add sorting and filtering

Below code is working for excel to html conversion and partial sorting.
I want when any cells in the header(or first row) is clicked the entire table should get sorted
based on that column(either ascending or descending).
Note:Below Code is tested with any excel input file and supporting settings for activex in internet options in IE9.
<HTML>
<HEAD>
<TITLE>Test</TITLE> <script type="text/javascript" src="../jquery-latest.js"></script>
<script type="text/javascript">
</script>
<STYLE TYPE="text/css">body div * { font-family: Verdana; font-weight: normal; font-size: 10px; } body { background-color: #FFEEFF; } .tableContainer table { border: 0px solid #000000; } .tblHeader { font-weight: bold; text-align: center; background-color: #FFAAEE; color: black; } .oddRow, .evenRow { vertical-align: top; } .tblHeader td, .oddRow td, .evenRow td { border-left: 2px solid #FFFFFF; border-bottom: 0px solid #000000; border-top: 0px solid #000000;} .lastCol { border-right: 0px solid #000000; } .oddRow { background-color: #abcdef; } .evenRow { background-color: #f0f0f0; }</STYLE>
<script LANGUAGE="JavaScript">
function _ge(id) {
return document.getElementById(id);
}
function sortTable(){
var tbl = document.getElementById("tblExcel2Html").tBodies[0];
var store = [];
//alert(tbl.rows.length);
for(var i=0, len=tbl.rows.length; i<len; i++){
var row = tbl.rows[i];
//alert(row.cells[1].innerText);
var sortnr = parseFloat(row.cells[1].textContent || row.cells[1].innerText);
if(!isNaN(sortnr)){
alert(store.push([sortnr, row]));
//store.push([sortnr, row]);
}
}
store.sort(function(x,y){
//alert(x[0] - y[0]);
return x[0] - y[0];
});
//alert(store.length);
for(var i=0, len=store.length; i<len; i++){
alert(tbl.appendChild(store[i][1]));
//alert(tbl.appendChild(store[i][1]));
}
//alert(store);
store = null;
}
function convert2HTML() {
var ex;
try {
ex = new ActiveXObject("Excel.Application");
}
catch (e)
{
alert('Your browser does not support the Activex object.\nPlease switch to Internet Explorer.');
return false;
}
//alert(arraytext);
//var ef = ex.Workbooks.Open("D:\\JS_HTML5\\Vin\\Test.xlsx");
var ef = ex.Workbooks.Open("D:\\JS_HTML5\\docs\\filter4\\tests\\Test.xlsx");
var es = ef.Worksheets(1);
var colsCount = ef.Worksheets(1).UsedRange.Columns.Count;
//alert(colsCount);
var rowsCount = ef.Worksheets(1).UsedRange.Rows.Count;
//alert(rowsCount);
var rStart = parseInt(1,10);
var cStart = parseInt(1,10);
var cEnd = parseInt(colsCount,10);
var rEnd = parseInt(rowsCount,10);
var oc = _ge('tableContainer');
oc.innerHTML = '';
var tbl = document.createElement('TABLE');
tbl.id = 'tblExcel2Html';
tbl.border = '10';
tbl.cellPadding = '4';
tbl.cellSpacing = '0';
oc.appendChild(tbl);
var i,j,row,col,r,c;
for(i = rStart, r = 0; i <= rEnd; i++,r++) {
row = tbl.insertRow(r);
row.className = (i == rStart) ? 'tblHeader' : (i % 2 == 0) ? 'evenRow' : 'oddRow';
for(j = cStart, c = 0; j <= cEnd; j++,c++) {
col = row.insertCell(c);
col.className = (j == cEnd) ? 'lastCol' : '';
col.innerHTML = es.Cells(i,j).value || ' ';
}
}
ex.ActiveWorkbook.Close(true);
ex.Application.Quit();
ex = null;
sortTable();
}
</script>
</HEAD>
<BODY onload = "convert2HTML()">
<h2>Test</h2>
<hr><br>
<!-- <td colspan="6" align="CENTER"><INPUT TYPE="button" VALUE="Convert to HTML" ONCLICK="convert2HTML()"></td> -->
<div id="tableContainer"></div>
<div id="tblExcel2Html"></div>
<footer>
<br>
<center> ©Initial Draft V0.1 </center>
</footer>
<a href="Home.html" >Home</a>
</BODY>
Basically i want to convert excel to html with sorting and filtering support.
Thanks in Advance
Vinoth.S
The creation of the object by calling
ex = new ActiveXObject("Excel.Application");
works only in windows systems with Excel installed. I suggest you to use jqgrid as javascript data-viewer and a php library like phpexcel that parse the excel and return raw data.