I have a dynamic table in my webapplication. I want to save this table to the LocalStorage. I tried many things but nothing worked.
This is the HTML of the table:
jQuery(document).delegate('a.add-record_alg', 'click', function(e) {
e.preventDefault();
var content = jQuery('#sample_table_alg tr'),
size = jQuery('#tbl_posts_alg >tbody >tr').length + 1,
element = null,
element = content.clone();
element.attr('id', 'rec_alg-' + size);
element.find('.delete-record_alg').attr('data-id', size);
element.appendTo('#tbl_posts_body_alg');
element.find('.sn').html(size);
});
jQuery(document).delegate('a.delete-record_alg', 'click', function(e) {
e.preventDefault();
var didConfirm = confirm("Ruimte verwijderen?");
if (didConfirm == true) {
var id = jQuery(this).attr('data-id');
var targetDiv = jQuery(this).attr('targetDiv');
jQuery('#rec_alg-' + id).remove();
//regnerate index number on table
$('#tbl_posts_body_alg tr').each(function(index) {
//alert(index);
$(this).find('span.sn').html(index + 1);
});
return true;
} else {
return false;
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="wellclearfix">
<a class="btn btn-primary pull-right add-record_alg" data-added="0"><i class="glyphicon glyphicon-plus"></i> Toevoegen </a>
</div>
<div class="container-fluid" style="margin-left:1px ;">
<form enctype="multipart/form-data">
<table class="table table-stripped" id="tbl_posts_alg">
<thead style="background-color:#c7c8cc;">
<tr>
<th style="width: 100px ;">Nummer</th>
<th style="width: 350px;">Naam</th>
<th>Gebruiksfunctie</th>
<th>Gebruiksoppervlakte [m2]</th>
<th style="width: 111px;">Verwijderen</th>
</tr>
</thead>
<tbody id="tbl_posts_body_alg">
<tr id="rec_alg-1">
<td><input class="inputtext" type="text" name="" placeholder="Nummer"> </td>
<td><input class="inputtext" type="text" name="" placeholder="Naam"> </td>
<td>
<label for="functie"> </label>
<select class="functiedropdown" name="Functie" id="functie">
<option value="verkeersruimte">selecteer een functie!</option>
<option value="verkeersruimte">verkeersruimte</option>
<option value="meterruimte">meterruimte</option>
<option value="toiletruimte">toiletruimte</option>
<option value="verblijfsruimte">verblijfsruimte</option>
<option value="verblijfsruimte">techniekruimte</option>
<option value="verblijfsruimte">bergruimte</option>
<option value="verblijfsruimte">wasruimte</option>
<option value="verblijfsruimte">badruimte</option>
<option value="verblijfsruimte">onbenoemde ruimte</option>
</select>
</td>
<td><input class="inputtext" type="text" name="" placeholder="[m2]"></td>
<td><a class="btn btn-xs delete-record" data-id="1"><i class="glyphicon glyphicon-trash"></i></a></td>
</tr>
</tbody>
</table>
</div>
</form>
<div style="display:none;">
<table id="sample_table_alg">
<tr id="">
<td><input class="inputtext" type="text" name="" placeholder="Nummer"> </td>
<td><input class="inputtext" type="text" name="" placeholder="Naam"> </td>
<td>
<label for="functie"> </label>
<select class="functiedropdown" name="Functie" id="functie">
<option value="verkeersruimte">selecteer een functie!</option>
<option value="verkeersruimte">verkeersruimte</option>
<option value="meterruimte">meterruimte</option>
<option value="toiletruimte">toiletruimte</option>
<option value="verblijfsruimte">verblijfsruimte</option>
<option value="verblijfsruimte">techniekruimte</option>
<option value="verblijfsruimte">bergruimte</option>
<option value="verblijfsruimte">wasruimte</option>
<option value="verblijfsruimte">badruimte</option>
<option value="verblijfsruimte">onbenoemde ruimte</option>
</select>
</td>
<td><input class="inputtext" type="text" name="" placeholder="[m2]"></td>
<td><a class="btn btn-xs delete-record_alg" data-id="0"><i class="glyphicon glyphicon-trash"></i></a></td>
</tr>
</table>
</div>
</div>
</div>
preferably i want to store the table to the LocalStorage per table data, because i need some values later again on a different page. I tried saving the whole table to the LocalStorage which is possible, but what i said, i need the table data's later again.
Can someone please help me out? (i hope i explained it well xD)
Thanks in advance!