i'm working on the datatable column visibility but i don't want all the table columns should shown in the visibility dropdown, only few need to be shown
I have tried with DTColumnDefBuilder.newColumnDef(0).withTitle('Name').notVisble() but it removed the column didn't solved it
html code
<table class="table table-striped dataTable no-footer dtr-inline" datatable="ng" dt-options="dataDtOptions" dt-instance="dataDtInstance" width="100%" dt-columns="dataDtColumns" dt-column-defs="dataDtColumnDefs">
<thead>
<tr>
<th>column1</th>
<th>column2</th>
<th>column3</th>
<th>column4</th>
<th>column5</th>
<th>column6</th>
</tr>
</thead>
<tbody>
<tr style="cursor:pointer" ng-repeat="data in datas" >
<td>{{data[0]}}</td>
<td>{{data[1]}}</td>
<td>{{data[2]}}</td>
<td>{{data[3]}}</td>
<td>{{data[5]}}</td>
<td>{{data[6]}}</td>
</tr>
</tbody>
</table>
angulajs code
$scope.dataDtOptions = DTOptionsBuilder.newOptions()
.withDOM("<'row'<'col-sm-5'l><'col-sm-2 width-200 pull-right'B><'col-sm-5 pull-right'f>>" +"<'row'<'col-md-12't>>" +"<'row'<'col-sm-5'i><'col-sm-7'p>>")
.withPaginationType('full_numbers')
.withButtons([
'colvis',
{
extend: 'collection',
text: 'Export',
buttons: [
'csv',
'pdf'
]
}
]);
$scope.dataDtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withTitle('column1'),
DTColumnDefBuilder.newColumnDef(1).withTitle('column2'),
DTColumnDefBuilder.newColumnDef(2).withTitle('column3'),
DTColumnDefBuilder.newColumnDef(3).withTitle('column4'),
DTColumnDefBuilder.newColumnDef(4).withTitle('column5'),
DTColumnDefBuilder.newColumnDef(5).withTitle('column6'),
]
so i don't want the first and last column in column visibilty dropdown
You can do the following:
DTColumnBuilder.newColumnDef(0).withClass('hidden')
And in CSS if you don't already have bootstrap installed
.hidden { display: none; }
Related
I have a list of dates coming from API and one such date is like "2017-07-05T10:53:24.000Z"
Am displaying dates in first column in datatable. In controller am defining the column like
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date'),
DTColumnDefBuilder.newColumnDef(1).notSortable(),
....
];
HTML
<table datatable="ng" dt-options="dtOptions" dt-column-defs="dtColumnDefs">
<thead>
<tr class="table-header-color-yellow">
<th class="table-head-style">Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="review in reviews">
<td>{{review.date | date}}</td>
</tr>
</tbody>
</table>
How can i sort the dates in descending order as it is sorting in ascending order as of now?
Just set the order option :
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [[0, 'desc']])
Your usage of columnDefs is a little bit wrong. It should be
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date').notSortable()
];
Convert date part into dd/MM/yyyy
Then in controller use
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef([1]).withOption('type', 'date')
];
and Html should be like this
<table class="table table-hover" datatable="ng" dt-column-defs="dtColumnDefs">
I am showing list on table using html (table, tr, td) and angularJS. Table also contains filters on columns. Table is populating data properly and filters are working properly using AngularJS.
After doing some filtration, I want to get only visible rows in one of my angularJS's function.
How can I get only the Visible Rows of a Table in angularJS after Few Filters?
Please note that I am not using any checkboxes or radio buttons with data list.
Please see my code below:
var myapp=angular.module("myapp",[]);
myapp.controller('ctrcommodity',['$scope',function($scope) {
$scope.commodity={
allPreferredCommodity: [
{
"commodityId": "2016070011220000141",
"commodityName": "Computer (PC)"
},
{
"commodityId": "2016080011220000004",
"commodityName": "Laptop"
},
{
"commodityId": "2016070011220000032",
"commodityName": "Keyboard"
},
{
"commodityId": "2016080011220000054",
"commodityName": "Mouser"
}
]
};
$scope.getVisibleRows=function()
{
//want to get details of visible rows after filtration
}
}]);
<table border="1" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>Commodity Id</th>
<th>Commodity Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="txtcid" id="txtcid" ng-model="s.commodityId"></td>
<td><input type="text" name="txtcname" id="txtcname" ng-model="s.commodityName"></td>
</tr>
<tr ng-repeat="commoditylist in commodity.allPreferredCommodity | filter:s">
<td>{{commoditylist.commodityId}}</td>
<td>{{commoditylist.commodityName}}</td>
</tr>
<tr>
<td align="center" colspan="6" height="50">
<input type="button" value="Show Visible Rows" ng-click="getVisibleRows()">
</td>
</tr>
</tbody>
Do like the follwing . I am changing your function as
$scope.getVisibleRows=function(arrayData,s)
{
console.log(s);
$scope.filerList=$filter('filter')(arrayData,s);
alert( $scope.filerList);
//want to get details of visible rows after filtration
}
and similarly change it is html also like ng-click="getVisibleRows(commodity.allPreferredCommodity,s)"
dont forget to inject filter to controller like myapp.controller('ctrcommodity',['$scope','$filter',function($scope,$filter)
I want to repeat data in a table row. However, when i click a button in the last td of the row, I want Another row to show underneath it, and ONLY beneath that element.
I can repeat separate data using ng-repeat-show/end, but it repeats the secondary data over all the primary data rows. The code:
<table class="table table-bordered table-striped table-hover table-responsive">
<tr ng-repeat-start="data in product_data | filter:'Flexi Floor/Low Wall':true">
<td style="vertical-align:middle;">{{data.model_no_from}} + {{data.model_no_to}}</td>
<td style="vertical-align:middle;">{{data.cooling}}</td>
<td style="vertical-align:middle;">{{data.heating}}</td>
<td style="vertical-align:middle;"><span class="blue">{{data.nominal_cooling}}</span><span class="red">{{data.nominal_heating}}</span></td>
<td style="vertical-align:middle;">{{data.pipe_length}}</td>
<td style="vertical-align:middle;">{{data.system_listPrice | currency:"£"}}</td>
<td class="td_button"><button class="btn btn-default btn-block td_button_border" ng-click="add()">Select</button></td>
</tr>
<tr ng-repeat-end ng-show="show_row">
<td colspan="6">This will repeat</td>
</tr>
</table>
Here's a plunker example of what I think you're looking for: http://plnkr.co/edit/z7gYsKxNffwm78aiEgQX?p=preview
Basically if you model your table rows as an array of objects, the addRow() button click function should insert a new row object into your model and when Angular applies changes to the view, ng-repeat will take care of appending the new row.
So if this is the ng-repeat row of your table:
<tr ng-repeat="row in rows track by $index">
<td>{{$index}}</td>
<td>{{row.details}}</td>
<td><button ng-click="addRow($index)">Add Row</button></td>
</tr>
Then this addRow() function and model should accomplish what you're after:
$scope.rows = [
{ details: 'Originally row 0' },
{ details: 'Originally row 1' },
{ details: 'Originally row 2' }
];
$scope.addRow = function(index){
$scope.rows.splice( index+1, 0, { details: 'new row after clicking index '+index} );
};
I got a json of table which has columns and rows as below
$scope.table = {
Columns: [{Header:"22-Jul-15",SubHeaders: ["10:33 AM"]}
, {Header:"21-Jul-15",SubHeaders: ["03:40 AM"]}
, {Header:"17-Jul-15",SubHeaders: ["01:05 PM", "12:06 PM"]}]
, Rows:[{Items:[{Value:1},{Value:5},{Value:8},{Value:""}]}
,{Items:[{Value:2},{Value:6},{Value:9},{Value:""}]}
,{Items:[{Value:3},{Value:7},{Value:10},{Value:15}]}]
} //end of table
I want to display Columns.SubHeaders as Sub header row of a table.
Here what I tried, but did not work
<table class="table table-stripped table-bordered">
<thead>
<tr>
<th ng-repeat="col in table.Columns" colspan="{{col.SubHeaders.length}}">{{col.Header}}</th>
</tr>
<tr>
<td class="center text-black" ng-repeat="head in table.Columns[0].SubHeaders">{{head}}</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in table.Rows">
<td ng-repeat="item in row.Items">
{{item.Value}}
</td>
</tr>
</tbody>
</table>
I used head in table.Columns[0].SubHeaders just to show it is working for hard-coded index value.
How can I achieve this using single ng-repeat? I can use two ng-repeats but it will lead to unnecessary html markup.
Here is the complete fiddle
I created this fiddler (forked from yours):
https://jsfiddle.net/b50hvzef/1/
The idea is to join the subheaders as they are they actual columns:
<td class="center text-black" ng-repeat="head in subHeaders">{{head}}</td>
and the code looks like this:
var app = angular.module("app",[]);
app.controller("MyController", function ($scope, $http) {
$scope.table = {
Columns: [{Header:"22-Jul-15",SubHeaders: ["10:33 AM"]}
, {Header:"21-Jul-15",SubHeaders: ["03:40 AM"]}
, {Header:"17-Jul-15",SubHeaders: ["01:05 PM", "12:06 PM"]}]
,Rows:[{Items:[{Value:1},{Value:5},{Value:8}]}
,{Items:[{Value:2},{Value:6},{Value:9}]}
,{Items:[{Value:3},{Value:7},{Value:10}]}]
};
var subHeaders = [];
$scope.table.Columns.forEach(function(col) {
col.SubHeaders.forEach(function(subHeader) {
subHeaders.push(subHeader);
});
});
$scope.subHeaders = subHeaders;
});
Note that there is still a mismatch between columns and data. But it's up to you how to solve it.
Hope this helps.
I have used ng-scrollbar like this :
<tbody ng-scrollbar rebuild-on="rebuild:me" class="scrollme" id ="tempID">
and in ng table , included the broadcast
getData: function($defer, params) {
$scope.$broadcast('rebuild:me');
Now the ng-repeat is populating the tr in thead after first th instead of appending/loading it correctly in tbody
how to correctly display my results?
did you try this
getData: function($defer, params) {
$defer.promise.then(function(){
$scope.$broadcast('rebuild:me');
};
...
right after updating table
Edit 1
tbody is replacing by div and thus how layout became messy,check plunk
Edit 2
Here some workaround about this,need some editing,i will update later
Edit 3(final)
Finally get working example of ngtable and ngscrollbar together,but its not most beautiful solution but still:
1.
you need separate thead from rest of table into new table which locate right above main table
<thead>
<tr >
<th class="sortable" ng-class="{
'nameasc':'sort-asc' ,
'namedesc':'sort-desc'
}[sortTableParam]"
ng-click="SortBy('name')">
<div>name</div>
</th>
<th class="text-center sortable" ng-class="{
'ageasc':'sort-asc' ,
'agedesc':'sort-desc'
}[sortTableParam]"
ng-click="SortBy('age')">
<div>Age</div>
</th>
</tr>
</thead>
</table>
2.
second - hide thead in main table and wrap table into div tag,which will be processing by directive:
<div style="height:300px" ng-scrollbar rebuild-on="rebuild:me" class="scrollme">
<table ng-table="tableParams" show-filter="true" class="table">
<thead><tr><th ></th><th ></th></tr></thead>
<tbody >
<tr ng-repeat="user in $data">
<td data-title="'Name'" filter="{ 'name': 'text' }" sortable="name">
{{user.name}}
</td>
<td data-title="'Age'" sortable="age">
{{user.age}}
</td>
</tr>
</tbody>
</table>
</div>
3.
Clicks from header will trigger reloading data with sorting option,by binding SortBy function
var sorting = $scope.tableParams.$params.sorting;
var dir = sorting != null ? (sorting[param.toString()] == 'asc' ? 'desc' : 'asc') : 'asc';
var sort={};
sort[param.toString()]=dir;
$scope.tableParams.sorting(sort);
//edit classes in header for rows imaging(check plunk)
updatesorting(param);
};