<table id="table" class="table table-bordered font" style="width: 100%; padding-top:10px;">
<thead>
<tr class="bg-primary textalign">
<th>Details</th>
<th>SonVin Id</th>
<th>Date</th>
<th>Venue Name</th>
<th>City</th>
<th>Area</th>
<th>Amount</th>
<th><input type="checkbox" ng-model="checkall" /><span style="margin-left:10px;">Add Invoice</span></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in getdataintable">
<td>Details</td>
<td>{{data.sonvinid}}</td>
<td>{{data.date}}</td>
<td>{{data.venuename}}</td>
<td>{{data.location}}</td>
<td>{{data.area}}</td>
<td>{{data.amount}}</td>
<td><input type="checkbox" ng-model="check" /></td>
</tr>
</tbody>
</table>
This is my table,
here I have this line( <th><input type="checkbox" ng-model="check" /><span style="margin-left:10px;">Add All Invoice</span></th>).
This indicates that if a user checked this checkbox, all the other checkboxes should also be checked.
Now what I want is if a particular user clicks on a checkbox on thead, all the checkboxes of td also be check and all the data of <td>{{data.sonvinid}}</td>
should be stored in the array in my controller of angularjs.
$scope.storeall=[];
I want to do this with angularjs,
anyone here who can help me?
make inside your controller some methods like this
method to select All
method for deselect All
method for toggle between above
var app = angular.module('app',[]) // the app module
app.controller('tableCtrl',function($scope){
$scope.storeall = [];
$scope.selectAllFlag = false;
$scope.getdataintable = [
{sonvinid:1, date : "string" , venuename: "String Name" },
{sonvinid:2, date : "string" , venuename: "String Name" }
];
$scope.checkAllToggle = funciton(){
if(!$scope.selectAllFlag){
$scope.selectAll();
$scope.selectAllFlag = true;
}else {
$scope.deselectAll();
$scope.selectAllFlag = false;
}
};
$scope.selectAll = function(){
for (var i = 0 ; i < $scope.data.length ; i++){
$scope.getdataintable[i].selected = true;
$scope.storeall.push($scope.data[i].sonvinid);
}
};
$scope.deselectAll = function(){
for (var i = 0 ; i < $scope.data.length ; i++){
$scope.getdataintable[i].selected = false;
$scope.storeall = [];
}
};
});
to Use it on HTML:
<table id="table" class="table table-bordered font" ng-controller="tableCtrl" style="width: 100%; padding-top:10px;">
<thead>
<tr class="bg-primary textalign">
<th>Details</th>
<th>SonVin Id</th>
<th>Date</th>
<th>Venue Name</th>
<th>City</th>
<th>Area</th>
<th>Amount</th>
<th><input type="checkbox" ng-model="checkAllToggle()" /><span style="margin-left:10px;">Add Invoice</span></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in getdataintable">
<td>Details</td>
<td>{{data.sonvinid}}</td>
<td>{{data.date}}</td>
<td>{{data.venuename}}</td>
<td>{{data.location}}</td>
<td>{{data.area}}</td>
<td>{{data.amount}}</td>
<td><input type="checkbox" ng-checked="data.selected" /></td>
</tr>
</tbody>
</table>
Related
I have a table where I have some checkboxes but when I select them and click submit it doesn't do anything. The strangest thing is that if I place the tags inside as they suppose to be it doesn't work, I cant submit any values:
<thead>
<tr>
<th><input type="checkbox" name="select_all" value="1" id="example-select-all"></th>
<th>Dev.no</th>
<th>IMEI</th>
<th>Serial no.</th>
<th>Barcode</th>
<th>Device</th>
<th>Date added on stock</th>
<th>Report comment</th>
</tr>
</thead>
BUT , if I place the tags outside then it works, I am able to get the values HOWEVER table loses pagination:
<tr>
<thead>
<th><input type="checkbox" name="select_all" value="1" id="example-select-all"></th>
<th>Dev.no</th>
<th>IMEI</th>
<th>Serial no.</th>
<th>Barcode</th>
<th>Device</th>
<th>Date added on stock</th>
<th>Report comment</th>
</thead>
</tr>
Any idea why this weird behavior is happening? What am I doing wrong here?
UPDATE: jQuery code below
<script>
$(document).ready(function() {
$('#example').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': true,
'orderable': true,
'className': 'dt-body-center'
}]
});
});
$('#frm-example').on('submit', function(e) {
var form = this;
table.$('input[type="checkbox"]').each(function() {
if (!$.contains(document, this)) {
if (this.checked) {
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', this.name)
.val(this.value)
);
}
}
});
});
</script>
I Want to add search box for each column which will search in respective column. For that I have written my code as below but its not working.
home.component.html
<table class="table">
<tr>
<th>Commit Date</th>
<th>Commit Id</th>
<th >Environment</th>
<th>Jira Id's</th>
<th >Upgrade Date</th>
</tr>
<tr>
<th><input [(ngModel)]="searchString1" placeholder="Search.." class="advancedSearchTextbox"></th>
<th><input [(ngModel)]="searchString2" placeholder="Search.." class="advancedSearchTextbox"></th>
<th><input [(ngModel)]="searchStrin3" placeholder="Search.." class="advancedSearchTextbox"></th>
<th><input [(ngModel)]="searchStrin4" placeholder="Search.." class="advancedSearchTextbox"></th>
<th><input [(ngModel)]="searchString5" placeholder="Search.." class="advancedSearchTextbox"></th>
</tr>
<tr *ngFor="let data of history | filter :{ commit_date : searchString1, commit_id: searchString2, env: searchString3, jira_ids: searchString4, upgrade_date: searchString5};">
<td class="text-left">
{{data.commit_date}}
</td>
<td>{{data.commit_id}}</td>
<td>{{data.env}}</td>
<td>{{data.jira_ids}}</td>
<td>{{data.upgrade_date}}</td>
</tr>
</table>
filter.pipe.ts
import { Pipe, PipeTransform, Injectable } from '#angular/core';
#Pipe({
name: 'filter'
})
#Injectable()
export class FilterPipe implements PipeTransform {
transform(items: any, filter: any, defaultFilter: boolean): any {
if (!filter){
return items;
}
if (!Array.isArray(items)){
return items;
}
if (filter && Array.isArray(items)) {
let filterKeys = Object.keys(filter);
if (defaultFilter) {
return items.filter(item =>
filterKeys.reduce((x, keyName) =>
(x && new RegExp(filter[keyName], 'gi').test(item[keyName])) || filter[keyName] == "", true));
}
else {
return items.filter(item => {
return filterKeys.some((keyName) => {
return new RegExp(filter[keyName], 'gi').test(item[keyName]) || filter[keyName] == "";
});
});
}
}
}
}
It works fine if I add a single search box at top and change HTML file like below:
Search Data Here: </b><input [(ngModel)]="searchString" placeholder="Search.." class="advancedSearchTextbox">
<table class="table">
<tr>
<th>Commit Date</th>
<th>Commit Id</th>
<th >Environment</th>
<th>Jira Id's</th>
<th >Upgrade Date</th>
</tr>
<tr *ngFor="let data of history | filter :{ commit_date : searchString, commit_id: searchString, env: searchString, jira_ids: searchString, upgrade_date: searchString};">
<td class="text-left">
{{data.commit_date}}
</td>
<td>{{data.commit_id}}</td>
<td>{{data.env}}</td>
<td>{{data.jira_ids}}</td>
<td>{{data.upgrade_date}}</td>
</tr>
</table>
What changes do I need to make the search box work for each individual column
Use one parameter for the search input and use function that get the key and the name of the column as below:
HTML:
<table class="table">
<tr>
<th>Commit Date</th>
<th>Commit Id</th>
<th >Environment</th>
<th>Jira Id's</th>
<th >Upgrade Date</th>
</tr>
<tr>
<th><input placeholder="Search.." class="advancedSearchTextbox" [ngModel]="searchString" (ngModelChange)="search($event,'commit_date')" ></th>
<th><input placeholder="Search.." class="advancedSearchTextbox" [ngModel]="searchString" (ngModelChange)="search($event,'commit_id')"></th>
<th><input placeholder="Search.." class="advancedSearchTextbox" [ngModel]="searchString" (ngModelChange)="search($event,'env')"></th>
<th><input placeholder="Search.." class="advancedSearchTextbox" [ngModel]="searchString" (ngModelChange)="search($event,'jira_ids')"></th>
<th><input placeholder="Search.." class="advancedSearchTextbox" [ngModel]="searchString" (ngModelChange)="search($event,'upgrade_date')"></th>
</tr>
<tr *ngFor="let data of filterData">
<td class="text-left">
{{data.commit_date}}
</td>
<td>{{data.commit_id}}</td>
<td>{{data.env}}</td>
<td>{{data.jira_ids}}</td>
<td>{{data.upgrade_date}}</td>
</tr>
</table>
TS:
history = [
{
commit_date: "20/02/2019",
commit_id: "52",
env: "log",
jira_ids: "jira",
upgrade_date: "02/03/2019"
},
{
commit_date: "03/03/2019",
commit_id: "53",
env: "log",
jira_ids: "jira",
upgrade_date: "03/04/2019"
}
];
searchString="";
filterData:any=[];
constructor(){
this.filterData = this.history;
}
search(term,columnName){
if(!term) {
this.filterData = this.history;
} else {
this.filterData = this.history.filter(x =>
x[columnName].trim().toLowerCase().includes(term.trim().toLowerCase())
);
}
}
I have an angularjs table that looks like this:-
Here is the code below:-
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="CheckCtrl">
<table class="table table-hover data-table sort display" style="width:100%">
<thead>
<tr>
<th class="Serial_">
Serial
</th>
<th class="Name_">
Name
</th>
<th class="ID_">
ID
</th>
<th class="On_off_">
On/off
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in check_items">
<td>{{item.SERIAL}}</td>
<td>{{item.NAME}}</td>
<td>{{item.ID}}</td>
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-click="rowSelected(item)"></td>
</tbody>
</table>
</div>
<script>
var app = angular.module('app',[]);
app.controller('CheckCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.check_items =
[
{
SERIAL:'Test Serial',
NAME:'Test Name',
ID : 10,
ON_OFF : '1'
}
];
$scope.rowSelected = function(row)
{
console.log(row);
};
}]);
</script>
When the checkbox is unchecked. I want a hyperlink text "Link" containing the URL 127.0.0.1/{{item.SERIAL}} to appear beside the checkbox. When the checkbox is checked an ordinary text "Checked" will appear beside the checkbox.
I am using angularjs v1.
Try this,
Should change the ON_OFF value while click on check box.
$scope.rowSelected = function(row)
{
row.ON_OFF = (row.ON_OFF=='1')?'0':'1';
};
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="CheckCtrl">
<table class="table table-hover data-table sort display" style="width:100%">
<thead>
<tr>
<th class="Serial_">
Serial
</th>
<th class="Name_">
Name
</th>
<th class="ID_">
ID
</th>
<th class="On_off_">
On/off
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in check_items">
<td>{{item.SERIAL}}</td>
<td>{{item.NAME}}</td>
<td>{{item.ID}}</td>
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-click="rowSelected(item)">
<a ng-show="item.ON_OFF=='0'" ng-href="127.0.0.1/{{item.SERIAL}}">LINK</a>
<span ng-show="item.ON_OFF=='1'">CHECKED</span>
</td>
</tbody>
</table>
</div>
<script>
var app = angular.module('app',[]);
app.controller('CheckCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.check_items =
[
{
SERIAL:'Test Serial',
NAME:'Test Name',
ID : 10,
ON_OFF : '1'
}
];
$scope.rowSelected = function(row)
{
row.ON_OFF = (row.ON_OFF=='1')?'0':'1';
};
}]);
</script>
You can add conditional span checking value of the ON_OFF model like below:
<td>
<input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-click="rowSelected(item)">
<span ng-if="item.ON_OFF == '1'">Checked</span>
<span ng-if="item.ON_OFF != '1'"><a ng-href="127.0.0.1/{{item.SERIAL}}">Link</a></span>
</td>
I am using knockout binding to bind some data into html tables. My knockout view Model had multiple products and each product will have multiple chars. I want to display the products in one table and when i select the link "show chars" it should display the corresponding chars in below table.
This is my View Model
var ProductViewModel = function(items) {
this.items = ko.observableArray(items);
this.itemToAdd = ko.observable("");
this.addItem = function() {
if (this.itemToAdd() != "") {
this.items.push(this.itemToAdd());
this.itemToAdd("");
}
}.bind(this);
};
And this is my html tables
<div id="productTable">
<table class="ui-responsive table">
<thead>
<tr>
<th >Product Name</th>
<th >Description</th>
<th >Parent?</th>
</tr>
</thead>
<tbody id="pBody" data-bind="foreach: items">
<tr class="success" >
<td><span data-bind="text: name"></span>
</td>
<td><span data-bind="text: desc"></span>
</td>
<td>show chars</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="productChars">
<div id="productCharTable">
<table class="ui-responsive table">
<thead>
<tr>
<th >Char Name</th>
<th >Description</th>
<th >Length</th>
<th >Type</th>
</tr>
</thead>
<tbody id="pBody" data-bind="foreach: $data['chars']">
<tr class="success">
<td><span data-bind="text: name"></span>
</td>
<td>asdf asdfasdf</td>
<td>10</td>
<td>String</td>
</tr>
</tbody>
</table>
</div>
I am able to bind the products into first table. But for characteristics i am not sure how to achieve the same.
Could someone please help me in figuring out how to achieve the same.
Here is the jsfiddle
https://jsfiddle.net/sirisha_k/0Ln7h2bo/7/
As #supercool pointed out you can use "data-bind='with selectedItem'" to populate the second table with chars data. For that you need to add one more item into your model called selectedItem and every time you select or add a row, you point the selectedItem to that elementdata. And use "data-bind='with selecteItem'" for second table.
var ProductViewModel = function(items) {
this.items = ko.observableArray(items);
this.selectedItem = ko.observableArray();
this.itemToAdd = ko.observable("");
this.addItem = function() {
if (this.itemToAdd() != "") {
this.items.push(this.itemToAdd());
this.itemToAdd("");
}
}.bind(this);
};
and on row select call some function selectedItem($data) where $data refers to the current item.
then set that data to selectedItem in model.
function selectedItem(prod){
ProductViewModel.selectedItem(prod);
}
I have implemented paging using PageList.MVC. Now I need to that i can change the pagesize from my web.config. Any idea ....
Here is my controller:
public ActionResult UsersWhoHaveConsumedFreeCredit(int Id = 1)
{
var result = Manager.GetUsersWhoHaveConsumedFreeCredit();
JavaScriptSerializer serializer = new JavaScriptSerializer();
var model = serializer.Deserialize<List<CallHistory>>(result);
int pageSize = 100;
//int pageNumber = (page ?? 1);
return View(model.ToPagedList(Id, pageSize));
}
And this is my view
#model PagedList.IPagedList<MyYello.Admin.Models.CallHistory>
#{
ViewBag.Title = "UsersWhoHaveConsumedFreeCredit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Users Who Have Consumed Free Credit</h2>
#*<table class="table table-striped table-bordered tablesorter" style="display: block">
<thead>
<tr>
<th>Login</th>
<th>FirstName</th>
<th>LastName</th>
<th>Email</th>
<th>Country</th>
<th>TarrifDesc</th>
<th>CalledNum</th>
<th>CallStart</th>
<th>CallEnd</th>
</tr>
</thead>*#
#foreach (var group in Model.GroupBy(dialed => dialed.Login))
{
var item = group.First();
{
<table>
<tbody>
<th class="custom-padding">Login Id</th>
<th class="custom-padding">Phone</th>
<th class="custom-padding">First Name</th>
<th class="custom-padding">Last Name</th>
<th class="custom-padding">Email</th>
<th class="custom-padding">Country</th>
<tr>
<td class="custom-padding">#item.Login </td>
<td class="custom-padding">#item.Phone</td>
<td class="custom-padding">#item.FirstName</td>
<td class="custom-padding">#item.LastName</td>
<td class="custom-padding">#item.Email</td>
<td class="custom-padding">#item.Country</td>
<th class="custom-padding">Dialed Calls:-</th>
<td class="custom-padding">#string.Join(" - ", group.Select(dialed => dialed.DialedNumber))</td> </tr>
#*<td>#item.FirstName</td>
<td>#item.LastName</td>
<td>#item.Email</td>
<td>#item.Country</td>*#
#*<td>#string.Join(" - ", group.Select(history => history.Phone))</td>*#
<tr> #*<td>#item.TariffDescription</td>*#
</tr>
</tbody>
</table>
<hr />
}
}
#* #Html.PagedListPager( (IPagedList)ViewBag.pageNumber, page => Url.Action ("UsersWhoHaveConsumedFreeCredit", new {page}));*#
<div class="paged-list">
#Html.PagedListPager(Model, Id => Url.Action("UsersWhoHaveConsumedFreeCredit", new { Id }), PagedListRenderOptions.Classic)
</div>
#if (!Model.Any())
{
<h2>No Record Found</h2>
}
I don't think you want this to be controlled from web.config however, you can do this by having a key inside appsettings section in web.config file.
<appSettings>
<key name="pageSize" value="10"/>
</appSettings>
And then you can access inside your code as
int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pageSize"])
Typically you would want users to control pageSize from the view.