-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_table_add_delete.html
More file actions
84 lines (78 loc) · 2.68 KB
/
Copy pathdynamic_table_add_delete.html
File metadata and controls
84 lines (78 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery dynamic table</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<style>
body{ margin:20px auto;}
button{ margin-right:10px;}
button:first-child{ margin-right:0;}
</style>
</head>
<body>
<div class="container">
<div class="form-group clearfix">
<div class="row">
<div class="col-sm-7">
<div class="row">
<div class="col-xs-8">
<input type="text" placeholder="Enter Sl. no." class="form-control" id="rowno"/>
</div>
<div class="col-xs-4">
<button class="btn btn-danger" data-action="deleterow">Delete</button>
</div>
</div>
</div>
<div class="col-sm-5">
<button class="btn btn-danger pull-right" data-action="deletelastrow">Delete Last Row</button>
<button class="btn btn-danger pull-right" data-action="deletefirstrow">Delete First Row</button>
</div>
</div>
</div>
<div class="form-group clearfix">
<div class="row">
<div class="col-sm-7">
<div class="row addvalueBox">
<div class="col-sm-6">
<input type="text" placeholder="Enter City1" class="form-control"/>
</div>
<div class="col-sm-6">
<input type="text" placeholder="Enter City2" class="form-control"/>
</div>
</div>
</div>
<div class="col-sm-5">
<button class="btn btn-success" data-action="addlastrow">Add</button>
</div>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="dynamicTable.js"></script>
<script>
$(document).ready(function() {
$(".container").createTable({
"thead": ["Sl. No.","City 1", "City 2"],
"tbody": [
["1","New York", "LA"],
["2","Paris", "Milan"],
["3","Pittsburg", "Wichita"]
]
});
//remove table row
$("button").click(function() {
var getSelection = $(this).attr("data-action");
var gettxt = $("#rowno").val();
$(".container").deleteRow(gettxt,getSelection);
});
//add table row
$("button").click(function() {
var getSelection = $(this).attr("data-action");
var slno = $('.table tbody tr:last td:first').text();
$(".container").addRow(slno,getSelection);
});
});
</script>
</body>
</html>