I am follwing this bootsnip code in https://bootsnipp.com/snippets/BE93p
for creating a dynamic table in bootstrab, it insert a new filed after clicking add row button and dynamically calculate the total price after filling the inputs.
but I git this error after inserting a new row?!
htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp\htdocs\laundry\vendor\blade-ui-kit\blade-ui-kit\resources\views\components\forms\inputs\input.blade.php)
the Blade page:
<div class="container">
<div class="row clearfix">
<div class="col-md-12">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center"> # </th>
<th class="text-center"> Product </th>
<th class="text-center"> Qty </th>
<th class="text-center"> Price </th>
<th class="text-center"> Total </th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td>1</td>
<td><input type="text" name='product[]' placeholder='Enter Product Name' class="form-control"/></td>
<td><input type="number" name='qty[]' placeholder='Enter Qty' class="form-control qty" step="0" min="0"/></td>
<td><input type="number" name='price[]' placeholder='Enter Unit Price' class="form-control price" step="0.00" min="0"/></td>
<td><input type="number" name='total[]' placeholder='0.00' class="form-control total" readonly/></td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12">
<button id="add_row" class="btn btn-default pull-left">Add Row</button>
<button id='delete_row' class="pull-right btn btn-default">Delete Row</button>
</div>
</div>
<div class="row clearfix" style="margin-top:20px">
<div class="pull-right col-md-4">
<table class="table table-bordered table-hover" id="tab_logic_total">
<tbody>
<tr>
<th class="text-center">Sub Total</th>
<td class="text-center"><input type="number" name='sub_total' placeholder='0.00' class="form-control" id="sub_total" readonly/></td>
</tr>
<tr>
<th class="text-center">Tax</th>
<td class="text-center"><div class="input-group mb-2 mb-sm-0">
<input type="number" class="form-control" id="tax" placeholder="0">
<div class="input-group-addon">%</div>
</div></td>
</tr>
<tr>
<th class="text-center">Tax Amount</th>
<td class="text-center"><input type="number" name='tax_amount' id="tax_amount" placeholder='0.00' class="form-control" readonly/></td>
</tr>
<tr>
<th class="text-center">Grand Total</th>
<td class="text-center"><input type="number" name='total_amount' id="total_amount" placeholder='0.00' class="form-control" readonly/></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){b=i-1;
$('#addr'+i).html($('#addr'+b).html()).find('td:first-child').html(i+1);
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
calc();
});
$('#tab_logic tbody').on('keyup change',function(){
calc();
});
$('#tax').on('keyup change',function(){
calc_total();
});
});
function calc()
{
$('#tab_logic tbody tr').each(function(i, element) {
var html = $(this).html();
if(html!='')
{
var qty = $(this).find('.qty').val();
var price = $(this).find('.price').val();
$(this).find('.total').val(qty*price);
calc_total();
}
});
}
function calc_total()
{
total=0;
$('.total').each(function() {
total += parseInt($(this).val());
});
$('#sub_total').val(total.toFixed(2));
tax_sum=total/100*$('#tax').val();
$('#tax_amount').val(tax_sum.toFixed(2));
$('#total_amount').val((tax_sum+total).toFixed(2));
}
please help me to fix that error
Had fixed this issue simmply by adding type="button"
in the button tags
<button type="button" id="add_row" class="btn btn-default pull-left">Add Row</button>
<button type="button" id='delete_row' class="pull-right btn btn-default">Delete Row</button>
Related
I am iterating a object and displaying the result on a table.
HTML:
<div id="app">
<div id="app">
<p> SeletedId's {{ selectedIds }}</p>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr class="text-center">
<th>
<span class="badge badge-info">Select</span>
</th>
<th>
<span class="badge badge-success">Name</span>
</th>
</tr>
</thead>
<tbody v-for="(pay,i) in PaymentType" :key="i">
<tr>
<td>
<input type="checkbox" v-model="selectedIds" :value="{selectedId: pay.Id}" />
</td>
<td>{{pay.Name}}</td>
</tr>
<!---I wanted to show the input box here -->
</tbody>
</table>
</div>
</div>
Vue:
new Vue({
el: '#app',
created(){},
data: {
message: 'Hello Vue.js!',
PaymentType: [{
Id: 1,
Name: "Cash",
HasOtherField: false,
Remarks: ""
},
{
Id: 2,
Name: "Check",
HasOtherField: false,
Remarks: ""
},
{
Id: 3,
Name: "Others",
HasOtherField: true,
Remarks: ""
}
],
selectedIds: []
}
})
I wanted to show a div or a row with a input box below the table. That should show/hide with the check box checked or unchecked.
For Hiding or showing the the input box i am implemented the following:
<div v-show="selectedIds[i]">
<span>Remarks</span><input type="text" class="form-control"/>
</div>
This is what i have done so far. The label Remarks and input box is not properly in-line.
I have manage to display the input box in-line by adding the following <tr></tr>
on the above code.
<tr v-show="selectedIds[i]">
<td colspan="2">
<span>Remarks</span>
<input type="text" class="form-control" />
</td>
</tr>
On My final template
<div id="app">
<div id="app">
<p> SeletedId's {{ selectedIds }}</p>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr class="text-center">
<th>
<span class="badge badge-info">Select</span>
</th>
<th>
<span class="badge badge-success">Name</span>
</th>
</tr>
</thead>
<tbody v-for="(pay,i) in PaymentType" :key="i">
<tr>
<td><input type="checkbox" v-model="selectedIds" :value="{selectedId: pay.Id}" /></td>
<td>{{pay.Name}}</td>
</tr>
<tr v-show="selectedIds[i]">
<td colspan="2">
<span>Remarks</span>
<input type="text" class="form-control" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
Fiddle!
Use the template for the loop instead of the tbody, and v-if instead of v-show:
<template v-for="(pay, i) in PaymentType">
<tr :key="i*2">
<td>
<input type="checkbox" v-model="selectedIds" :value="pay.Id" />
</td>
<td>{{pay.Name}}</td>
</tr>
<tr :key="i*2 + 1" v-if="selectedIds.indexOf(pay.Id) !== -1">
<td> </td>
<td>
Remarks <input type="text" class="form-control" v-model="pay.Remarks" />
</td>
</tr>
</template>
[ https://jsfiddle.net/dcr202yn/ ]
I have a Bootstrap page showing a title with 2 forms in a single row above a table. The 2nd form with the 2 inputs which appears in the top left above the table is taking up the full width of the parent column (col-md-8) - it only needs to take up around half of this column width.
I can't work out how to position this so it takes up less space but still aligns with the left of the title/table at the same time. Here's how it currently looks (make sure your use the full page option to see this as it will be used on desktop only):
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8">
<h1>Items List</h1>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form class="form-horizontal" id="findItems" action="#" method="get" role="form">
<input type="hidden" name="action" value="findItems">
<table class="table table-bordered">
<tr>
<td><input type="text" class="form-control" name="itemID" id="itemID" placeholder="Shipment ID"></td>
<td><input type="text" class="form-control datepicker" name="shippingDate" id="shippingDate" data-date-format="dd/mm/yyyy" placeholder="Date Shipped"></td>
<td class="text-center">
<button type="submit" class="btn btn-success">Update All</button>
</td>
</tr>
</table>
</form>
</div>
<!-- /.col-md-8-->
<div class="col-md-4">
<div>
<form class="form-horizontal" id="findMoreItems" action="#" method="get" role="form">
<input type="hidden" name="action" value="findMoreItems">
<table class="table table-bordered">
<tr>
<td>Shipment ID:</td>
<td><input type="text" class="form-control" name="shipmentID" id="shipmentID" placeholder="Shipment ID"></td>
</tr>
<tr>
<td>Authority ID:</td>
<td><input type="text" class="form-control" name="authorityID" id="authorityID" placeholder="Authority ID"></td>
</tr>
<tr>
<td>Ref ID:</td>
<td><input type="text" class="form-control" name="refID" id="refID" placeholder="Ref ID"></td>
</tr>
<tr>
<td>Serial Number:</td>
<td><input type="text" class="form-control" name="serialNumber" id="serialNumber" placeholder="Serial #"></td>
</tr>
<tr>
<td colspan="2" class="text-center">
<button type="reset" class="btn btn-default">Reset</button>
<button type="submit" class="btn btn-success">Search</button>
</td>
</tr>
</table>
</form>
</div>
</div>
<!-- /.col-md-4-->
</div>
<!-- /.row-->
<br>
<div>
<br />
<table class="table table-condensed table-striped table-bordered">
<thead>
<th class="text-center" scope="col">Shipment ID</th>
<th class="text-center" scope="col">Item ID</th>
<th class="text-center" scope="col">Serial Number</th>
<th class="text-center" scope="col">Shipped Date</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div><!-- /.container -->
You could always just add a spacer column. So...
<div class="col-md-6"> two table things </div>
<div class="col-md-2"> empty column for spacing </div>
<div class="col-md-4"> other table </div>
This question already has answers here:
Make 2 buttons inside a table cell be next to each other
(5 answers)
Closed 6 years ago.
I have a problem to make the button in table side by side. I have tried table-responsive but it didn't work. I really hope that you can help me.
Here is my code. Based on my understanding, table-responsive or table table-bordered table-hover is from Bootstrap. As long I link it in my index.html, supposedly it should be fine.
But now my output is not as I desired. The button that I have circle should be side by side
P/S: sorry for my english.
<div class=" table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>PPMID</th>
<th>EPRID</th>
<th>Release ID</th>
<th>Project Name</th>
<th>Release Name</th>
<th>Application Name</th>
<th>Action</th>
</tr>
<tr>
<th>
<input class="form-control" id="ppmid" type="number" min="1" placeholder="PPMID">
</th>
<th>
<input class="form-control" id="eprid" type="number" min="1" placeholder="EPRID">
</th>
<th>
<input class="form-control" id="releaseid" type="text" placeholder="Release ID">
</th>
<th>
<input class="form-control" id="projectname" type="text" placeholder="Project Name">
</th>
<th>
<input class="form-control" id="releasename" type="text" placeholder="Release Name">
</th>
<th>
<input class="form-control" id="applicationname" type="text" placeholder="Application Name">
</th>
<th>
<button class="btn btn-primary">
<span class="glyphicon glyphicon-plus"></span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in filteredlist | filter:searchText"><!--false for ascending, true for descnding-->
<td>{{item.PMID}}</td>
<td>{{item.EPRID}}</td>
<td>{{item.Releaseid}}</td>
<td>{{item.projectname}}</td>
<td>{{item.releasename}}</td>
<td>{{item.appname}}</td>
<td>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-edit"></span>
</button>
<button type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
There is no problem with your code. It works just fine. Button side by side
Maybe you should try checking if your browser is not in a zoom-in mode or check if the resolution is correct.
Live Demo Here
Snippet Example
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class=" table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>PPMID</th>
<th>EPRID</th>
<th>Release ID</th>
<th>Project Name</th>
<th>Release Name</th>
<th>Application Name</th>
<th>Action</th>
</tr>
<tr>
<th>
<input class="form-control" id="ppmid" type="number" min="1" placeholder="PPMID">
</th>
<th>
<input class="form-control" id="eprid" type="number" min="1" placeholder="EPRID">
</th>
<th>
<input class="form-control" id="releaseid" type="text" placeholder="Release ID">
</th>
<th>
<input class="form-control" id="projectname" type="text" placeholder="Project Name">
</th>
<th>
<input class="form-control" id="releasename" type="text" placeholder="Release Name">
</th>
<th>
<input class="form-control" id="applicationname" type="text" placeholder="Application Name">
</th>
<th>
<button class="btn btn-primary">
<span class="glyphicon glyphicon-plus"></span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in filteredlist | filter:searchText"><!--false for ascending, true for descnding-->
<td>{{item.PMID}}</td>
<td>{{item.EPRID}}</td>
<td>{{item.Releaseid}}</td>
<td>{{item.projectname}}</td>
<td>{{item.releasename}}</td>
<td>{{item.appname}}</td>
<td>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-edit"></span>
</button>
<button type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
I think <td> do not have enough width for the buttons make them side-by-side.
Two solutions:
.side-by-side {
display: -webkit-flex;
display: flex;
flex-wrap: nowrap; // force buttons not line-break
}
add this CSS for the container <td>.
(btw, flex is CSS3 property, check browser support here)
or give enough fixed width for the <td>.
I have this picture below that I want to convert into web from a windows. I manage to do the design but I have a problem in the grid (I am using data tables in bootstrap) I can't do the design in what in the picture like.
<table>
<tr>
<td>
<div>
<input type="radio" />
Radio Button
</div>
</td>
<td>
<input type="radio" />
Radio Button
</td>
</tr>
<tr>
<td>
<div>
<input type="text" />
</div>
</td>
<td>
< div>
< input type="button" />
</div>
</td>
</tr>
</table >
<table >
<tr>
<td>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
< i class="fa fa-list fa-fw" >< / i >Table
< /div >
< /div>
< /div>
< !-- /.panel-heading -->
< div class="panel-body">
< div class="dataTable_wrapper">
< table class="table table-striped table-bordered table-hover table-responsive nowrap"
role="grid" style="width: 100%;" id="dataTables-xxxx">
</table>
</div>
</div>
</div>
</div>
< /div>
</td>
<td>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
< i class="fa fa-list fa-fw"></i>Table
< /div>
< /div>
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover table-responsive nowrap"
role="grid" style="width: 100%;" id="dataTables-xxasdxx">
</table>
< /div>
< /div>
< /div>
< /div>
< /div>
</ td>
< /tr>
< /table>
My 2 Images bellow:
Try the below design hope it helps.You can customize the column property as your desire I just added the basic skeleton.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container">
<div class="row">
<div class=" col-sm-12 form-group">
<div class=" col-sm-2">
<input type="radio" />
Radio Button
</div >
<div class=" col-sm-2">
<input type="radio" />
Radio Button
</div >
</div >
<div class=" col-sm-12 form-group ">
<div class=" col-sm-2">
<input type="text" class="form-control" id="usr">
</div>
<div class=" col-sm-2">
<button type="button" class="btn btn-default">Submit</button>
</div>
</div>
<div class="table-responsive col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1">#</th>
<th class="col-md-2">Header</th>
<th class="col-md-3">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1">#</th>
<th class="col-md-2">Header</th>
<th class="col-md-3">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
Or See the below fiddle for a better look
table design demo fiddle (updated)
You can also, do something like this instead of using tables for layout and mimic as close as to your conversion UI.
table tags are meant primarily for data formatting. Bootstrap has the concept of grid layout which is meant for laying out your UI without using tables.
When you open the snippet in full screen, you would see the exact replica. However, when the screen is too small to fit in your entire content, it just wraps into the next row, giving you the flexibility to build responsive layout, which is not possible with table tags.
.custom-margin {
margin-top: 10px;
margin-bottom: 10px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="custom-container">
<div class="radio">
<label class="radio-inline">
<input type="radio" name="" id="optionsRadiosOne" value="optionOne">Radio Button One
</label>
<label class="radio-inline">
<input type="radio" name="" id="optionsRadiosTwo" value="optionTwo">Radio Button Two
</label>
</div>
<div class="custom-margin">
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Enter Email :</label>
<input type="text" class="form-control" placeholder="Enter Email">
</div>
<button type="submit" class="btn btn-primary">Send invitation</button>
</form>
</div>
<div class="row">
<div class="col-lg-3">
<table class="table table-hover">
<tr>
<td>Header One
</td>
<td>Header Two
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
</table>
</div>
<div class="col-lg-6">
<table class="table table-hover">
<tr>
<td>Header One
</td>
<td>Header Two
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
</table>
</div>
</div>
</div>
i am trying to set th width but it change only desktop view.
if i open that page in mobile table th not properly set.
i have also try col-xs-2 to fix th but it is not work
<div class="form-group col-lg-12 col-md-12 col-xs-12">
<div class="col-lg-12 col-md-12 col-xs-12 col-md-offset-1">
<div class="row" >
<div class = "table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr class="info">
<th class="col-md-2 col-xs-2" > No</th>
<th class="col-md-4 col-xs-4">Dish Name</th>
<th class="col-md-2 col-xs-2"> Size</th>
<th class="col-md-2 col-xs-2">Prize</th>
<th class="col-md-2 col-xs-2">Order</th>
</tr>
</thead>
<tbody>
<tr title="Order Chicken Kadhai">
<td >1</td>
<td >Chicken Kadhai</td>
<td >Full</td>
<td >150/-</td>
<td ><input type="button" class="btn btn-info" value="ORDER"> </td>
</tr>
<tr>
<td >2</td>
<td >Chicken Roast</td>
<td >Full</td>
<td >250/-</td>
<td ><input type="button" class="btn btn-info" value="ORDER"> </td>
</tr>
<tr>
<td >3</td>
<td >Chicken Tandori</td>
<td >Full</td>
<td >350/-</td>
<td ><input type="button" class="btn btn-info" value="ORDER"> </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
how can we set th to responsive table
From comments:
columns are not made for use in tables. .table-responsive adjusts
itself according to the content.
use this code might be help for you
<div class="table-responsive">
<table class="table">
...
</table>
</div>
write <class=".table-responsive>" instead of class=<class="table-responsive>"