I have tried for a while to duplicate the jquery insert row / insert column functionality that I have working for an html table to a css table. I have searched and experimented for a solution without success.
Here is the fiddle to to my work, I took out my attempted code because it was useless.
My code is listed below.
Thanks for any help.
html
div class="ws-css-table" >
<div class="ws-css-table-tr">
<div class="ws-css-table-td" id="1"></div>
<div class="ws-css-table-td" id="2"></div>
</div>
<div class="ws-css-table-tr">
<div class="ws-css-table-td" id="3"></div>
<div class="ws-css-table-td" id="4"></div>
</div>
</div>
<br/>
<button id="css-irow">CSS-Insert Row</button><button id="css-icol">CSS-Insert Column</button><br/><br/>
<br/>
<br/>
<table border="1" id="mtable">
<tbody>
<tr>
<td class="container"></td>
<td class="container"></td>
</tr>
<tr>
<td class="container">a</td>
<td class="container">b</td>
</tr>
</tbody>
</table><br/>
<button id="irow">Insert Row</button>
<button id="icol">Insert Column</button><br/><br/>
<br/>There are <span id="rowcount"></span> rows
<br/>There are <span id="colcount"></span> columns
jquery
$('#css-irow').click(function(){
});
$('#css-icol').click(function(){
});
////////////////////////////////////////////
$('#irow').click(function(){
$("#mtable tbody tr:last").clone().appendTo('#mtable tbody').find("td").empty();
var rowCount = $('#mtable tr').length;
$("#rowcount").text(rowCount)
});
////////////////////////////////////////////
$('#icol').click(function(){
$('#mtable tr').append($("<td class='container'>"));
$('#mtable thead tr>td:last').html($('#col').val());
$('#mtable tbody tr').each(function(){$(this).children('td:last').append($(''))});
var col = $('#mtable tbody tr:first > td').length;
$("#colcount").text(col);
});
css
.ws-css-table {
display: table;
}
.ws-css-table-tr {
display: table-row;
}
.ws-css-table-td {
display: table-cell;
border:1px solid #000;
width: 20px;
height:20px;
text-align:center;
vertical-align:middle;
}
This can be accomplished in the following way. This uses the same method you used and clones the divs into their respective locations.
Run the code snippet below ::
$('#css-irow').click(function(){
$(".ws-css-table-tr:last").clone().appendTo('.ws-css-table');
});
$('#css-icol').click(function(){
$(".ws-css-table-td:last").clone().appendTo('.ws-css-table-tr');
});
.ws-css-table {
display: table;
}
.ws-css-table-tr {
display: table-row;
}
.ws-css-table-td {
display: table-cell;
border:1px solid #000;
width: 20px;
height:20px;
text-align:center;
vertical-align:middle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ws-css-table" >
<div class="ws-css-table-tr">
<div class="ws-css-table-td"></div>
<div class="ws-css-table-td"></div>
</div>
<div class="ws-css-table-tr">
<div class="ws-css-table-td"></div>
<div class="ws-css-table-td"></div>
</div>
</div>
<br/>
<button id="css-irow">CSS-Insert Row</button><button id="css-icol">CSS-Insert Column</button><br/><br/>
This should help you get started.
Related
Hi I want to replace a div that is already displayed with another Hidden div choosed when i click on one of them(3 other divs(hidden) initially). the 4 links related to the 4 divs and in same way i can do that in each link clicked. below is the code:
<script type="text/javascript">
#4 Id of divs
var models = document.getElementById('models')
var geometry = document.getElementById('geometry')
var assembly = document.getElementById('assembly')
var loads = document.getElementById('loads')
#4 ID OF links (related to each div)
var models1 = document.getElementById('models1')
var geometryy = document.getElementById('geometryy')
var assemblyy = document.getElementById('assemblyy')
var loads1 = document.getElementById('loads1')
geometryy.addEventListener("click", function () {
models.style.display = "none"
loads.style.display = "none"
assembly.style.display = "none"
geometry.style.display = "block"
})
assemblyy.addEventListener("click", function () {
geometry.style.display = "none"
models.style.display = "none"
loads.style.display = "none"
assembly.style.display = "block"
})
loads1.addEventListener("click", function () {
geometry.style.display = "none"
models.style.display = "none"
assembly.style.display = "none"
loads.style.display = "block"
})
models1.addEventListener("click", function () {
models.style.display = "block"
geometry.style.display = "none"
assembly.style.display = "none"
loads.style.display = "none"
})
</script>
CSS:
<style>
#loads {
display: none;
}
#geometry {
display: none;
}
#assembly {
display: none;
}
#models {
display: block;
}
</style>
some Html code about the 4 divs:
<form action="{% url 'results' %}" method="post" id="gallery" novalidate onsubmit="return mySubmitFunction(event)">
<div style="padding-top: 10px; margin-left:138px;" class="parallax-window tm-section tm-section-gallery tm-flex background " id="models" >
<div style=" background-color: white; font-size:89%; width: 62rem; height: 32rem; margin-left:2.5rem; ">
<div class="card-warning" style="background-color: #C0C0C0;">
<nav class="navbar">
<a class="floated" style="font-weight: bolder; border-style: solid;" id="models1">Models</a>
Geometry
Assembly
Loads
</nav>
</div>
.......... some fields related to the div id="models"
</div>
</div>
----------------About the second div
<div style="padding-top: 10px;" class="parallax-window tm-section tm-section-gallery tm-flex" id="geometry" >
<div style=" background-color: white; font-size:89%; width: 62rem; height: 32rem; margin-left:2.5rem; ">
<div class="card-warning" style="background-color: #C0C0C0;">
<nav class="navbar">
Models
<a class="floated" style=" font-weight: bolder; border-style: solid;">Geometry</a>
Assembly
Loads
</nav>
</div>
<div style="display: flex;">
<div>
<img style="height: 372px; width:270px; margin-left: 25px;">
</div>
<div style="line-height: 0.001; margin-left: 10px; margin-top: 12px;">
------ some code for some fields
</div>
</div>
...... </div>
---- </div>
----------------About the third div
<div style="padding-top: 10px;" class="parallax-window tm-section tm-section-gallery tm-flex" id="assembly" >
<div style="background-color: white; font-size:89%; width: 62rem; height: 32rem; margin-left:2.5rem; ">
<div class="card-warning" style="background-color: #C0C0C0;">
<nav class="navbar">
Models
Geometry
<a class="floated" style=" font-weight: bolder; border-style: solid;">Assembly</a>
<a href="#loads" class="floated" style=" font-weight: bolder;" id="loads3" >Loads</a>
</nav>
</div>
<div style="display: flex;">
<div>
<img style="height: 372px; width:270px; margin-left: 25px;">
</div>
<div style="line-height: 0.001; margin-left: 10px; margin-top: 12px;">
------ some code for some fields
</div>
</div>
...... </div>
---- </div>
----------------About the fourth div
<div style="padding-top: 10px; " class="parallax-window tm-section tm-section-gallery tm-flex" id="loads" >
<div style="background-color: white; font-size:89%; width: 62rem; height: 32rem; margin-left:2.5rem;">
<div class="card-warning" style="background-color: #C0C0C0;">
<nav class="navbar">
<a href="#models" class="floated" style="font-weight: bolder;" >Models</a>
Geometry
Assembly
<a style=" font-weight: bolder; border-style: solid;">Loads</a>
</nav>
</div>
<div style="display: flex;">
<div>
<img style="height: 372px; width:270px; margin-left: 25px;">
</div>
<div style="line-height: 0.001; margin-left: 10px; margin-top: 12px;">
------ some code for some fields
</div>
</div>
...... </div>
---- </div>
</form>
what i want :at first the "models" div is shown and the other 3 divs("geometry",assembly","loads") are hidden , so i want when i click on "geometry" div , the first div "models" become hidden and the other divs ("assembly" and "loads" still hidden) and so on if click on assembly... i i want to apply that on every div(because evry div has the 4 links)
But it doesn't give me any result!
<html>
<head>
<style>
#div2, #div3, #div4{
display: none;
}
</style>
</head>
<body>
<div style="background-color: #C0C0C0 ;padding-top: 10px;width: 62rem; height: 32rem; ">
<div>
<a href="#models" class="geo wy" style="border-style: solid;" >Models</a>
Geometry
Assembly
Loads
</div>
<div id="div1" class="wy hid">
Models and other stuffs here
</div>
<div id="div2" class="pk hid">
Geometry and other stuffs here
</div>
<div id="div3" class="fk hid">
Assembly and other stuffs here
</div>
<div id="div4" class="gk hid">
Loads and other stuffs here
</div>
</div>
<script>
window.onload = btn() ;
function btn() {
var query = document.querySelectorAll(".geo") ; //No of hrefs
var pts = document.querySelectorAll(".hid"); //No of divs
for(var i=0;i<query.length;i++){
query[i].addEventListener("click", function() { //know which href is being clicked currently
var cla = this.getAttribute('class').split(' ')[1] ; //get second class of current href which would be wy, pk, fk, gk respectively.
var point = document.querySelectorAll("."+cla)[1]; //selecting the div as, [0] would select the href
for(var j=0;j<pts.length;j++){
pts[j].style.display = "none"; //hid all the div
query[j].style.border= "none"; //remove all the href border
}
this.style.border= "solid"; //Add currently clicked href border
point.style.display = "block"; //display currently clicked div
})
}
}
</script>
</body>
</html>
Sorry the id and classes name are given random i am not good at naming. Please don't hesitate to ask if you are confused
I'm working on C# mvc project, and I'm trying to load product cart partial view, where I want in each row to have a button Read More for product specification. When users click on Read more it should collapse in div where specification for product are loaded.
I manage to accomplish this by creating css style for div Id - product-intro, but It functioning just on first row.
I'm now trying to dynamically create div Id's and also style inline product-intro"+"-"+i and I cant manage working.
Thanks in advance for any suggestions.
Here is my html:
#{int i = 0;}
#foreach (var line in Model.Lines)
{
var validQuantityClass = line.Quantity <= line.InStock ? "" : "danger";
<tr class="article #validQuantityClass" id="article-#line.Product.ProductId">
<td>
<div class="media">
<h4 class="group inner list-group-item-heading">#line.Product.Name</h4>
#{i++;}
<script>articleSpec()</script>
<div class="media-body">
<div id="#("product-intro"+"-"+i)" class="collapse" style="margin-bottom: 10px; border-bottom:1px solid #dee2e6; padding:10px 0; font-size: 12px;">
<div class="row justify-content-between">
<div class="col">
<span id='#string.Format("article-{0}-spec", line.Product.tecId)'></span>
</div>
</div>
</div>
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#product-intro-#i">Read More +</button>
</div>
</div>
</td>
</tr>
}
Javascript:
<script>
function articleSpec() {
$("#product-intro").each(function (index) {
var articleId = document.getElementById('tecId').value;
if (!articleId)
return;
var labelSelector = "#article-" + articleId + "-spec";
var url = "/Search/ArticleSpecification";
var postdata = "articleid=" + articleId;
$.post(url,
postdata,
function (data) {
$(labelSelector).html(data);
});
});
}
</script>
And this is my css for product-intro:
.cart-content #product-intro {
margin-bottom: 10px;
border-top: 1px solid #dee2e6;
border-bottom: 1px solid #dee2e6;
padding: 10px 0;
font-size: 12px;
}
I also tried to pass #i in javascript and dynamically load data in div:
function articleSpec(number) {
$("#product-intro" + '-' + number).each(function (index) {
I have a HTML page. This has a grid created using DIV tags and display property set as table and inner DIV's having display properties as table-row and table-cell. If I need to export such table to excel, is there a way to do it in JavaScript? As of now only way I could think of is rewriting those DIV into html TABLE tags.
<div class="tablediv" id="tablediv">
<div class="tablerow">
<div class="tablecell">
A
</div>
<div class="tablecell">
B
</div>
</div>
<div class="tablerow">
<div class="tablecell">
1
</div>
<div class="tablecell">
2
</div>
</div>
</div>
.tablediv {
display: table;
}
.tablerow {
display: table-row;
}
.tablecell {
display: table-cell;
}
$("#btnExport").click(function(e) {
//Convert DivTable to Table
let TBLDiv=$("<div/>",{id:"TBLDivMain"});
let TBL=$("<table/>");
let TBO=$("<tbody/>");
$('#tablediv .tablerow').each(function(key,value){
let TR=$('<tr/>');
$(value).find(".tablecell").each(function(key,value){
let TD=$('<td/>',{text:$(value).text()});
TR.append(TD);
});
TBO.append(TR);
});
TBL.append(TBO);
TBLDiv.append(TBL);
//Export to Excel
var file = new Blob([TBLDiv.html()], {type:"application/vnd.ms-excel"});
var url = URL.createObjectURL(file);
var a = "<a id='Dow' href='"+url+"' download='filename.xls' ></a>";
$("body").append(a);
var CickDownload= document.getElementById('Dow');
CickDownload.click();
$("body #Dow").remove();
e.preventDefault();
});
.tablediv {
display: table;
}
.tablerow {
display: table-row;
}
.tablecell {
display: table-cell;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="btnExport" value=" Export Table data into Excel " />
<br/>
<br/>
<div class="tablediv" id="tablediv">
<div class="tablerow">
<div class="tablecell">A</div>
<div class="tablecell">B</div>
</div>
<div class="tablerow">
<div class="tablecell">1</div>
<div class="tablecell">2</div>
</div>
</div>
I'm using Bootstrap 3.2. I'm trying to figure out if there's a way to show/hide a "col-sz-#" div AND change the "col-sz-#" class in visible divs to resize them to fit the container using checkbox style buttons for each column.
For example, if I start with
<div class="row">
<div class="col-md-2">...</div>
<div class="col-md-2">...</div>
<div class="col-md-2">...</div>
<div class="col-md-2">...</div>
<div class="col-md-2">...</div>
<div class="col-md-2">...</div>
</div>
Then if hide 2 of them and the others resize:
<div class="row">
<div class="col-md-2 hidden">...</div>
<div class="col-md-2 hidden">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
</div>
if the total columns can't divide 12 evenly like 5, then it wouldn't change.
You can do this:
var $myCols = $("#myColumns");
$("#toggleColumns input").change(function() {
var index = +this.value - 1;
var visible = this.checked;
$($myCols.children().get(index)).toggle(visible);
resizeColumns();
});
function resizeColumns() {
var visibleCols = $myCols.children(":visible").length;
var div = Math.floor(12 / visibleCols);
var rem = 12 % visibleCols;
var colSize = (rem === 0) ? div : 2;
$myCols.children().removeClass().addClass('col-md-'+colSize);
}
Demo in jsFiddle
UPDATE:
If you want to act on multiple identical rows, just find all of them with a selector and call a function on each row:
$(".resizeRow").each(function(){
var $eachRow = $(this);
// Do Stuff
});
Updated Fiddle
This is how I solved the issue, I adapted it from https://codepen.io/feger/pen/deIki.
$("input:checkbox:not(:checked)").each(function() {
var column = "table ." + $(this).attr("name");
$(column).hide();
});
$("input:checkbox").click(function(){
var column = "table ." + $(this).attr("name");
$(column).toggle();
});
.clearfix:before,.clearfix:after {
content: " ";display: table; /* 2 */}
.clearfix:after {clear: both;}
.clearfix {*zoom: 1;}
.options {margin-bottom: 8px;}
/* Style checkboxes as Toggle Buttons */
.ck-button {
margin:2px;
background-color:#EFEFEF;
border-radius:4px;
border:1px solid #aaa;
overflow:auto;
float:left;
color:#aaa;
}
.ck-button:hover {
background-color:#ddd;
}
.ck-button label {
float:left;
width:auto;
margin-bottom: 0;
}
.ck-button label span {
text-align:center;
padding:3px 8px;
display:block;
}
.ck-button label input {
position:absolute;
top:-20px;
}
.ck-button input:checked + span {
color:#111;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>
<body>
<div class="options clearfix">
<div class="ck-button">
<label><input type="checkbox" value="1" name="first_name" checked="checked"><span>First Name</span></label>
</div>
<div class="ck-button">
<label><input type="checkbox" value="1" name="last_name" checked="checked"><span>Last Name</span></label>
</div>
<div class="ck-button">
<label><input type="checkbox" value="1" name="email"><span>Email</span></label>
</div>
</div>
<table class="table table-striped table-bordered table-hover table-condensed">
<thead>
<tr>
<th class="first_name">First Name</th>
<th class="last_name">Last Name</th>
<th class="email">Email</th>
</tr>
</thead>
<tbody>
<tr>
<td class="first_name">Larry</td>
<td class="last_name">Hughes</td>
<td class="email">larry#gmail.com</td>
</tr>
<tr>
<td class="first_name">Mike</td>
<td class="last_name">Tyson</td>
<td class="email">mike#gmail.com</td>
</tr>
</tbody>
</table>
</body>
</html>
Check out this fiddle. Here, I used jquery toggle to show/hide the elements. I think, the fiddle will be a good starting point for you. You can also do this with css (without jquery). Then, you have to set
the display: none property.
How can I make a ''spoiler'' but instead of a button there's a image? Here's the code I used.
<style type="text/css">
body,input
{
font-family:"Trebuchet ms",arial;font-size:0.9em;
color:#333;
}
.spoiler
{
border:1px solid #ddd;
padding:3px;
}
.spoiler .inner
{
border:1px solid #eee;
padding:3px;margin:3px;
}
</style>
<script type="text/javascript">
function showSpoiler(obj)
{
var inner = obj.parentNode.getElementsByTagName("div")[0];
if (inner.style.display == "none")
inner.style.display = "";
else
inner.style.display = "none";
}
</script>
<div class="spoiler">
<input type="button" onclick="showSpoiler(this);" value="Show/Hide" />
<div class="inner" style="display:none;">
This is a spoiler!
</div>
</div>
It isn't necessary to use this code, I only want it to be an image instead of a button.
It's working fine with me: http://jsfiddle.net/48PBY/
<div class="spoiler">
<img onclick="showSpoiler(this);" src="https://pbs.twimg.com/profile_images/858514627/eppaa_bigger.jpg" />
<div class="inner" style="display:none;">
This is a spoiler!
</div>
</div>
<a href="javascript:;" onclick="showSpoiler(this);" >
<img src="image/path"></a>
try this