I'm trying to add a Materialize dropdown inside a table generate with *ngFor and the dropdown didn't show.
If I put the dropdown code outside the table it works.
<p>Users enabled in this node: {{usersEnabled}}</p>
<p>Users in this node: {{users.length}}</p>
<table>
<thead>
<th>
Email
</th>
<th>
Enabled
</th>
<th>
Actions
</th>
</thead>
<tbody>
<tr *ngFor="let user of users">
<td>
{{user.username}}
</td>
<td class="isLink cursorIcon" (click)="enableDisableUser(user.apiKey)">
{{user.enabled}}
</td>
<td>
<!-- Dropdown Structure -->
<!-- <button class="btn" (click)="resetPassword(user)">Reset password</button> -->
<a class='dropdown-trigger btn' data-target='dropdown{{user.apiKey}}'>Drop Me!</a>
<ul id='dropdown{{user.apiKey}}' class='dropdown-content'>
<li>one</li>
<li>two</li>
<li class="divider" tabindex="-1"></li>
<li>three</li>
<li><i class="material-icons">view_module</i>four</li>
<li><i class="material-icons">cloud</i>five</li>
</ul>
</td>
</tr>
</tbody>
</table>
Typescript important methods
ngOnInit() {
this.getUsers();
}
private getUsers(): void {
this.userService.getUsersByNodeApiKey(this.nodeKey).subscribe(
res => {
this.usersEnabled = res.filter((user: User) => user.enabled).length;
this.users = res.sort((a, b) => a.enabled < b.enabled ? 1 : -1);
M.AutoInit();
var elems = document.querySelectorAll('.dropdown-trigger');
var instances = M.Dropdown.init(elems, {autoTrigger: true});
},
err => console.error(err)
);
}
I'm using Angular 8 and Materialize CSS 1.0
For that you need to add [innerHTML] which enables generated html inside your table like this
[innerHTML]="user.dropdown"
Where as user.dropdown may be an empty string defined in your .ts file or some value which you want to use in drop-down.
May be in your case user.apiKey can also be used.
Try rendering the table / row in the view once users scope has it's data by add a
<ng-container *ngIf="users.length">
<tr *ngFor="let user of users">
.
.
.
</tr>
</ng-container>
Hope this helps!
Hey #Marc Serret i Garcia... I have found a work around. Try if my provided solution works:-
<tbody>
<tr *ngFor="let user of users">
<td>
{{user.username}}
</td>
<td class="isLink cursorIcon" (click)="enableDisableUser(user.apiKey)">
{{user.enabled}}
</td>
<td>
<!-- Dropdown Structure -->
<!-- <button class="btn" (click)="resetPassword(user)">Reset password</button> -->
<a class='dropdown-trigger btn' [attr.data-target]='user.apiKey'>Drop Me!</a>
<ul [id]='user.apiKey' class='dropdown-content'>
<li>one</li>
<li>two</li>
<li class="divider" tabindex="-1"></li>
<li>three</li>
<li><i class="material-icons">view_module</i>four</li>
<li><i class="material-icons">cloud</i>five</li>
</ul>
</td>
</tr>
</tbody>
Look for the changes that I have made -
<a class='dropdown-trigger btn' [attr.data-target]='user.apiKey'>Drop Me!</a>
And the other for the id of dropdown - <ul [id]='user.apiKey' class='dropdown-content'>. It worked for me. Hope this helps.
Please look at my stackblitz:- https://stackblitz.com/edit/multipledropdown
Related
I'm trying to add the Gentelella template to my ASP.NET Core project.
The main problem is that the content of my current pages (any index page) is not merged with the template:
Expected Value:
Current Value:
The problem:
I'm trying to figure out how to show these components (index view inside and layout) together, as shown in picture 1.
For this, I found the code inside the _Layout that encapsulates the Plain Page section:
Should I make the call of my index view in that section? How?
PartialView rings a bell.
Calling the Controllers and actions:
<li>
<a><i class="fa fa-edit"></i> Tiendas <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li><a asp-area="" asp-controller="Stores" asp-action="Index">Nueva Tienda</a></li>
<li>Editar Tiendas</li>
</ul>
</li>
Section inside the Template where the Index should show:
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Plain Page</h2>
<ul class="nav navbar-right panel_toolbox">
<li>
<a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
</li>
<li class="dropdown">
<i class="fa fa-wrench"></i>
<ul class="dropdown-menu" role="menu">
<li>
Settings 1
</li>
<li>
Settings 2
</li>
</ul>
</li>
<li>
<a class="close-link"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
Add content to the page ...
</div>
</div>
</div>
</div>
Example of Index View:
#model IEnumerable<Application.Models.Tienda>
#using Application.Models
#{
ViewData["Title"] = "Index";
}
#Html.Partial("_NavBar")
<h2>Tiendas</h2>
#*data-toggle tells bootstrap what to do*#
#*data-target tells bootstrap which element is going to open*#
<div class="btn-group" id="modalbutton">
<a id="createEditStoreModal" data-toggle="modal" asp-action="Create" data-target="#modal-action-store"
class="btn btn-primary">
<i class="glyphicon glyphicon-plus"></i> Nueva Tienda
</a>
</div>
<p></p>
<table id="stores" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>
Provincia
</th>
<th>
Marca Comercial
</th>
<th>
Cadena
</th>
<th>
Tienda
</th>
<th>Editar</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Districts.Provincias.provincia_nombre)
</td>
<td>
#Html.DisplayFor(modelItem => item.tienda_marca)
</td>
<td>
#Html.DisplayFor(modelItem => item.tienda_cadena)
</td>
<td>
#Html.DisplayFor(modelItem => item.tienda_nombre)
</td>
<td>
<div class="btn-group" id="modalbuttonedit">
<a id="editStoreModal" data-toggle="modal" asp-action="Create"
data-target="#modal-action-store" asp-route-id="#item.tienda_id" class="btn btn-info">Edit</a>
</div>
</td>
</tr>}
</tbody>
</table>
Solved it.
The proper way to position your Index view inside the _Layout is using the #RenderBody() wherever you want to load your view information.
In this case, it was where I indicated it in the question.
There is also the option to render your scripts, if any. #RenderSection("Scripts", required: false)
We have to be careful with that since the script might run locally but not once the project is in production because of bad placement.
The final picture is this:
Hi I'm trying to obtain responsive menu on navbar in application on which I work with bootstrap 3. My menu has element with bell icon. The purpose of this one is to remind user some information. Below I show that menu element on screen:
I have fixed settings for width of my menu. I'd like to have responsive menu, not static, because this application should work on few screen resolutions. What should I obtain that? I tried to obtain that by pecrentage property for: width, min-with properties, but it has crashed.
Below I show html tags and CSS settings:
Html:
<li class="dropdown ng-isolate-scope open" loader="remainderLoading"><a ng-show="!loader" id="reminderLink" class="dropdown-toggle" data-toggle="dropdown" style="font-size:18px; cursor:pointer;" ng-click="removeNotification()" aria-expanded="true"><i class="fa fa-bell"></i></a>
<!-- ngIf: numOfRemindedNotes && !loader && !clicked -->
<div id="reminderMenu" class="dropdown-menu">
<div class="form-group col-md-7 disabled">
<label>Reminder's date:</label>
<input type="text" class="form-control ng-pristine ng-untouched ng-valid ng-isolate-scope ng-not-empty ng-valid-date ng-valid-required" ng-change="getNotesByDate()" initdate="new Date()" ng-click="noteDatepicker.opened = true" uib-datepicker-popup="" ng-model="dateNotes.value" is-open="noteDatepicker.opened" ng-required="true" close-text="Close" readonly="" required="required"><div uib-datepicker-popup-wrap="" ng-model="date" ng-change="dateSelection(date)" template-url="uib/template/datepickerPopup/popup.html" class="ng-pristine ng-untouched ng-valid ng-scope ng-not-empty"><!-- ngIf: isOpen -->
</div>
</div>
<div ng-show="noteLoading" class="ng-hide">
<img width="32" height="32" src="/packages/img/loader.gif">
</div>
<div class="col-md-12">
<table id="reminderTable" class="table table-bordered table-striped" ng-show="!noteLoading">
<tbody>
<tr id="reminderTableElement">
<td class="col-md-3">
Case Id
</td>
<td class="col-md-3">
Trans id
</td>
<td class="col-md-3">
Type customer
</td>
<th class="col-md-3">
Note
</th>
<td class="col-md-3">
Date
</td>
<td class="col-md-3"></td>
</tr>
<!-- ngRepeat: note in notes.notesForBasicCustomer --><tr ng-repeat="note in notes.notesForBasicCustomer" id="reminderTableElement" class="ng-scope">
<td style="cursor: pointer;">
<a target="_self" ng-click="editCaseById(note.case_id)" class="ng-binding">426024</a>
</td>
<td class="ng-binding">
639252-2
</td>
<td>Basic</td>
<td class="ng-binding">
asdsadsa
</td>
<td class="ng-binding">
2018-08-09
</td>
<td>
<div class="btn btn-primary" ng-disabled="noteLoading" ng-click="hideReminder(note['0'].id,'basic')">Close
</div>
</td>
</tr><!-- end ngRepeat: note in notes.notesForBasicCustomer --><tr ng-repeat="note in notes.notesForBasicCustomer" id="reminderTableElement" class="ng-scope">
<td style="cursor: pointer;">
<a target="_self" ng-click="editCaseById(note.case_id)" class="ng-binding">426011</a>
</td>
<td class="ng-binding">
639252-2
</td>
<td>Basic</td>
<td class="ng-binding">
asdsa
</td>
<td class="ng-binding">
2018-08-09
</td>
<td>
<div class="btn btn-primary" ng-disabled="noteLoading" ng-click="hideReminder(note['0'].id,'basic')">Close
</div>
</td>
</tr><!-- end ngRepeat: note in notes.notesForBasicCustomer -->
<!-- ngRepeat: note in notes.notesForAdditionalCustomers -->
</tbody>
</table>
</div>
</div>
</li>
CSS:
#reminderTableElement{
font-size: 12px;
}
#reminderMenu{
min-width: 540px;
}
I would be grateful for help. Best regards ;)
You should use #media tags to implement styles. For example
#media (min-width: 1600px) {
#reminder-menu {
...
}
}
It is considered best practice to design for mobile first, so you would use min-width: 540px or whatever your smallest breakpoint is first, then add more breakpoints as needed.
When I go to the last row (no. 25) and click edit you will see that the dropdown it's cropped out. Can you figure out how to solve this issue?
https://plnkr.co/edit/22e9bo?p=preview
<div ui-scroll-viewport class="col-md-12" style="height: 500px; border: dashed 1px #ddd;">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>id</th>
<th>source</th>
<th>destination</th>
</tr>
</thead>
<tbody>
<tr ui-scroll="item in datasource">
<td>{{item.id}} <a ng-click="showDropdown(item.id)">edit</a></td>
<td>{{item.source}}</td>
<td ng-if="dropdowns.active !== item.id">{{item.destination}}</td>
<td ng-if="dropdowns.active === item.id">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{item.destination}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li>10.0.0.0</li>
<li>10.255.255.255</li>
<li>172.16.0.0</li>
<li>172.31.255.255</li>
<li>192.168.255.255</li>
<li role="separator" class="divider"></li>
<li>192.168.0.0</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
Generally, this is not the ui-scroll issue, this is how the Bootstrap hosts it's dropdown menu in DOM. If the hoster element has overflow-y: scroll, then you'll get the situation you described in your question. As an angular-way solution I would suggest to use angular-ui wrapper for the Bootstrap: https://angular-ui.github.io/bootstrap/.
They have Dropdown directive which has dropdown-append-to and dropdown-append-to-body settings which allow you to append your Bootstrap dropdown to any element. This will solve the issue.
I am facing a complicated table design. I need to create a table with possible multiple tbodys. just like this:
As you can see, each tbody is for a date. and I need to add as many row as I want by clicking '+' icon for EACH date. and also can remove each row by clicking '-' icon. Now this is what I have done, but the new requirement is I need to add scroll bar for EACH tbody! (not for all table) each date(tbody) will show a scroll bar if I create more than 3 rows. as you can see, if I click '+' icon for date 01/08/2016, the scroll will appear on the right side of that tbody(only for this date leave other days alone.) How can I do it.
Here is my html:
<table class="table expensetable">
<thead>
<tr>
<th ng-hide="lodging.roomSameForAllDays">Date</th>
<th>Expense Type</th>
<th>Amount</th>
<th>Reimbursement</th>
<th ng-hide="lodging.sameDescriptionForAll">Description</th>
<th></th>
</tr>
</thead>
<tbody ng-repeat="day in lodging.roomData" ng-class="{'scroll-bar':getExpenseLength(day)}">
<tr ng-repeat-start="expense in day" class="ecom-components" ng-repeat-end>
<td ng-show="!lodging.roomSameForAllDays && ($index == 0)"
rowspan="{{day.length + 1}}"
style="vertical-align: top;">{{indexToDate($parent.$index) | date : companyDateFormat}}</td>
<td>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle clearfix" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="dropdown-label pull-left">{{expense.expenseType.expenseTypeName}}</span>
<span class="caret pull-right"></span>
</button>
<ul class="dropdown-menu">
<li ng-repeat="exp in roomRateTaxExpenseList | orderBy:'expenseTypeName'"><a href="javascript:void(0)"
ng-click="expense.expenseType = exp">{{exp.expenseTypeName}}</a></li>
<li></li>
</ul>
</div>
</td>
<td><input type="text" ecom-amount ng-model="expense.amount"></td>
<td>
<div class="dropdown" style="width:100%">
<button class="btn btn-default dropdown-toggle clearfix" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="dropdown-label pull-left">{{RNP_STATUSES[expense.rnp]}}</span>
<span class="caret pull-right"></span>
</button>
<ul class="dropdown-menu">
<li>Yes</li>
<li>No</li>
<li>Personal</li>
<li></li>
</ul>
</div>
</td>
<td ng-hide="lodging.sameDescriptionForAll"><input type="text" ng-model="expense.description"></td>
<td><span class="whitebutton remove" ng-click="deleteRow('roomData', $parent.$index, $index)"></span></td>
</tr>
<tr>
<td colspan="5"><span class="whitebutton add" ng-click="addRow('roomData', $index)"></span></td>
</tr>
</tbody>
</table>
Thanks in advance.
Here is what I have tried to, it is close but still didn't 100% match the requirement:
table.expensetable{
width:100%;
thead{
display:table;
width:100%;
}
tbody {
max-height:240px;
display:block;
tr{
display:table;
width:100%;
}
}
}
post js for more information:
$scope.getExpenseLength = function(day){
var isScroll = false;
if(day.length>3){
isScroll = true;
}else{
isScroll = false;
}
return isScroll;
}
As you can see, I can add scroll-bar to each tbody( which is cool) but the rowspan, doesn't work after scroll-bar appear or disappear. any update I need here?
We have done similar kind of thing in one of our project like below
var abc = $scope.$watch('grid.gridModel.data.data.items.length', function (newValue, oldValue) {
if (newValue > 4) { //grid should show a scrollbar after 3 rows
$scope.grid.gridOptions.autoheight = false;
if ($scope.grid.stateModel.gridObj) {
$($scope.grid.stateModel.gridObj.element).jqxGrid('height', '124px');
$($scope.grid.stateModel.gridObj.element).jqxGrid('refresh');
}
} else {
$scope.grid.gridOptions.autoheight = true;
if ($scope.grid.stateModel.gridObj) {
$($scope.grid.stateModel.gridObj.element).jqxGrid('height', 'auto');
$($scope.grid.stateModel.gridObj.element).jqxGrid('refresh');
}
}
});
Here what we are doing is, we are fixing the height of the grid if it contains more then 3 rows else it is of autoheight.
In your case if you can count number of rows in addRow( & deleteRow( function then you can also set height/max-height of the table. You might need to set overflow-y:auto while fixing the height.
Hope this helps.
I want a "large" table to be beautiful in both mobile devices and desktop. Without x-scrolling.
One way, I think, is to create a table row which is high (two rows, with rowspan=2).
But is there a smoother and more good-looking way to make this? This example below is okay, but I still think it's possible to make the result more clean and nicer.
One problem is also that I can't use ant filter plugins and pagination, as the scripts think that one row is two rows.
Any ideas?
<div class="container">
<div class="table-responsive">
<table class="table">
<tbody>
<tr class="bg-danger">
<td rowspan=2>
<div class="dropdown">
<button class="btn btn-danger dropdown-toggle btn-md" type="button" data-toggle="dropdown" onclick="">+
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Edit</li>
<li class="bg-danger">Delete</li>
</ul>
</div>
</td>
<td>
<div>
<h4>Christian A</h4></div>
</td>
<td>
<h4 class="pull-right">133 €</h4></td>
</tr>
<tr class="bg-danger">
<td colspan=2>
2014-05-05 - Not paid
</td>
</tr>
<tr class="bg-success">
<td rowspan=2>
<div class="dropdown">
<button class="btn btn-danger dropdown-toggle btn-md" type="button" data-toggle="dropdown" onclick="">+
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Edit</li>
<li class="bg-danger">Delete</li>
</ul>
</div>
</td>
<td>
<div>
<h4>Nicolaus S</h4></div>
</td>
<td>
<h4 class="pull-right">122 €</h4></td>
</tr>
<tr class="bg-success">
<td colspan=2>
2014-05-05 - Payed
</td>
</tr>
</tbody>
</table>
</div>
</div>
http://jsfiddle.net/weuf6vb3/