Skip to content

Instantly share code, notes, and snippets.

@IsmiKin
Created June 11, 2014 21:00
Show Gist options
  • Save IsmiKin/73ad184144166e32f9b8 to your computer and use it in GitHub Desktop.
Save IsmiKin/73ad184144166e32f9b8 to your computer and use it in GitHub Desktop.
A Pen by Ismael Ors.
<div class="large-3 large-4 columns">
<table class="responsive menutable">
<thead>
<tr><th>Name</th>
<th>Price</th>
<th>Actions</th>
</tr></thead>
<tbody>
<tr data-idmenu="1">
<td class="colname">
Ned Stark
</td>
<td class="colprice">
3000 €
</td>
<td class="colactions">
<button type="button" class="button radius small editButton"><i class="fa fa-edit fa-lg"></i></button>
<button type="button" class="button radius alert small deleteButton"><i class="fa fa-trash-o fa-lg"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="large-3 small-2 columns">
<input type="text" class="name" placeholder="name"/>
<input type="text" class="price" placeholder="price"/>
<button type="submit" class="button radius success createButton"><i class="fa fa-plus fa-lg"></i> &nbsp; Add new one</button>
</div>
<script id="newRow" type="text/x-handlebars-template">
<tr data-idMenu="{{idmenu}}">
<td class="colname">{{name}}</td>
<td class="colprice">{{price}} &euro;</td>
<td class="colactions">
<button type="button" class="button radius small editButton"><i class="fa fa-edit fa-lg"></i>
</button>
<button type="button" class="button radius alert small deleteButton"><i class="fa fa-trash-o fa-lg"></i>
</button>
</td>
</tr>
</script>
$(document).ready(function(){
$(".createButton").click(addNewRow);
});
function addNewRow(){
var source = $("#newRow").html();
var template = Handlebars.compile(source);
var number = 1 + Math.floor(Math.random() * 6);
var context = { idmenu: number , name: $(".name").val(), price: $(".price").val()};
var html = template(context);
$(".menutable tr:last").after(html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment