How to display a 5-14 column table in ionic 2 - ionic-framework

i have a requirement where presently im displaying the dynamic data using ion-col in that i m displaying column more than 8 Fields but it is not cumming responsive & here i require a suggestion how to display a table which have more than 5 max 14 fields using ionic 2

By default Ionic 2 grid comes with a 12 columns pattern, you can change it using SASS ans styling guides
Here's a link to Number of columns. What you need to do is simply add the following code in your variables.scss under theme folder:
$grid-columns: 14;
This will force your grid to have 14 columns instead of the default 12.
About the minimun of 5 columns there's no way to controll it, there's no minimun columns value, you'll need to proramatically assure that there's at least 5 columns, a way of doing this is using a total of columns that'll end up beeing represented in the screen as 5 columns, something like:
<ion-grid>
<ion-row>
<!-- assuming you're using 14 columns, if you're not all col- attributes must be col-2 -->
<ion-col col-3></ion-col>
<ion-col col-3></ion-col>
<ion-col col-3></ion-col>
<ion-col col-3></ion-col>
<ion-col col-2></ion-col>
</ion-row>
</ion-grid>
Hope this helps.

If you have maximum 14 columns requirement, then you need to do some customization.
Like, You have to divide 100% width by 14 (100/14= 7.14 %), Give width of 7.14% to the div or td you are using. and you will be able to manage 14 columns in your app.
.div_width{
width:7.14%;
display:inline-block;
}
<ion-list>
<ion-grid>
<ion-row>
<ion-col col-12 text-center>
<div class="div_width">
content here
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-list>

Related

Ionic - Limits of what can be pushed into [innerHTML]

I'm a volunteer at a Coffee Shop. I've built an app that presents the drink recipe to the barista. Here's a quick snapshot:
The data come from a firebase realtime database. Here's a snippet from that database:
What I want to do is to put some HTML into the instructions to format it for easy reading. I do that by binding the content in the template file to [innerHTML] as shown below:
<ion-item>
<ion-grid>
<ion-row *ngIf="!item.temperature">
<ion-col>
<ion-label><strong>Instructions</strong></ion-label>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<h5 *ngIf="this.compactMode">
<span [innerHTML]="item.instructions"></span>
</h5>
<span *ngIf="!this.compactMode" [innerHTML]="item.instructions">
</span>
</ion-col>
<ion-col *ngIf="item.image"
><ion-img
(click)="onClickImage(item.image)"
src="{{item.image}}"
></ion-img
></ion-col>
</ion-row>
</ion-grid>
</ion-item>
THE PROBLEM
This works really well for <b> <ol> <ul> <li> <br> and so on. But it does not work for <ion-checkbox> nor <input type="checkbox"> The input tags get filtered out somewhere before being presented.
SECURITY
I'm aware that putting HTML into a database can increase my security surface, so I'm using sanitizer to filter the HTML and then I attempt to add the after the fact. Here's how I do it:
stringFormat(inputString: string) {
const re1 = /\[\]/gi;
let returnString = this.sanitizer.sanitize(1, inputString);
returnString = returnString.replace(re1, '<ion-checkbox id=\'input\'></ion-checkbox>');
return returnString;
}
You'll notice that I first sanitize the string, and then I do a substitution, replacing [] with the checkbox.
(In case you're interested, I'm just making a opening/closing checklist and it would be nice if people could touch the checkbox after they've completed a task... I don't plan to store the checkbox values, I just want the checkbox user experience.)
I have checked that item.instructions in fact includes the substituted string in the item object, but when rendered by ionic/angular, the actual text seems to have filtered out anything but vanilla HTML tags.
Finally the Question
So here's the question: Are there some sort of limits to what can be inserted into the DOM using [innerHTML] binding? Am I overthinking this?
Thanks.
After reading https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML, I've concluded that there really is not a safe way to do this using the approach suggested above.
Instead of embedding HTML in the database, I'm going to set up an array of paragraphs in the item.instructions fields of the database. Each element in the array can have a key:value pair to indicate if the element represents a plain paragraph, or a checkbox.
Then I can iterate through the array of instructions (*ngFor), and for each instruction I can check the instruction type (<div *ngIf="item.type===...>) to determine whether to wrap the text with an <ion-text> or an <ion-checkbox>.

Bootstrap 4 - Image overflows from column when the window is resized

Bootstrap newbie here.
I'm trying to bootstrapify an old page but I can't seem to figure out how to stop my image from overflowing to the next column. I have a row with two columns- with the left side containing a picture. As soon as I reduce the window width, my image will start overflowing to the right column and will eventually collapse on top of the right column. I would like for the left column width to remain static or collapse to the top of the right column until the image can no longer fit in the left column.
I've tried adding the image-responsive class to the image but that will only change my image dimensions and I would prefer the image to keep its dimensions. Any help would be greatly appreciated!
Here is my code: https://www.codeply.com/go/fb14u8fsSc
Is it something like the one below you are looking for?
A couple of notes though:
It might be because of your simplified codeply example, but you use <div class="row"><div class="col-md-12">…X…</div></div>, which is the equivalent of …X…. That simplifies things.
We are talking about Bootstrap 4 here (you also use that in your codeply), but the .img-responsive class is from Bootstrap 3. That class is called .img-fluid in Bootstrap 4.
Regarding inline-style margins, I would suggest to use the spacing utility classes instead.
<div class="container-fluid" style="position: fixed">
<div class="row">
<div class="col">
<div class="card my-3">
<div class="card-header"></div>
<div class="card-body">
Insert name here<br/>
<img src="https://dummyimage.com/188x225/000/fff" class="XXXimg-fluid" alt=""/>
</div>
<div class="card-footer"></div>
</div>
</div>
<div class="col-md-9">
<div class="card text-xs-center mt-3">
<div class="card-header"></div>
<div class="card-body"></div>
</div>
</div>
</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>

Ionic: binding 3 dual knob range slides to a singel model

I am using Ionic 3 as a framework for my app. the app has a small configuration page. the user can choose different ranges via three dualknob sliders. the idea is, that those upper and lower limits are used to validate data which the user can enter on other pages. if a value is not between this range, the user gets an alert-toast.
im using firebase/angularfire2 as a database.
my html code with 3 sliders looks like this:
<ion-item>
<ion-label>Range 1</ion-label>
<ion-range min="-250" max="250" pin="true" dualKnobs="TRUE" [(ngModel)]="config.range1" color="secondary">
<ion-label range-left>-250g</ion-label>
<ion-label range-right>250g</ion-label>
</ion-range>
</ion-item>
<ion-item>
<ion-label>Range2</ion-label>
<ion-range min="0" max="200" pin="true" dualKnobs="TRUE" [(ngModel)]="config.range2" color="secondary">
<ion-label range-left>0</ion-label>
<ion-label range-right>200</ion-label>
</ion-range>
</ion-item>
<ion-item>
<ion-label>Range3</ion-label>
<ion-range min="0" max="200" pin="true" dualKnobs="TRUE" [(ngModel)]="config.range3" color="secondary">
<ion-label range-left>0</ion-label>
<ion-label range-right>200</ion-label>
</ion-range>
</ion-item>
I want to bind these three ranges to a single model to directly store it in firebase. So I created an interface, but I only manage to bind one range to this interface. the knobs of the other 2 ranges can't be moved and say "NaN" on their knobs. I tried to bind them to different elements of my interface called "config", but that didn't work. I also created fields called upper/lower in the limit but it didnt work.
Binding the ranges to three differentImodels worked. i then mapped it to my database model and saved them to firefase. but the other they round didnt work - the knobs didnt accept the values from the database.
thank you for your help.
Solved it myself by using a single model per Range-Slider and mapping the values in both directions to and from my database object before commiting.
slider1 = {} as any;
this.slider1.upper = (this.config.slider1max) ? this.config.slider1max : '100';
config.slider1max = this.slider1.upper;

Ion-slides slidesPerView property

I'm using ion-slides as the following:
<div *ngFor="let category of categories">
<h6 class="slide-title" [innerHTML]="category.name"></h6>
<ion-slides [loop]="true" [pager]="true" [slidesPerView]="3">
<ion-slide *ngFor="let product of category.products">
<img [src]="product.image" class="slide-image">
</ion-slide>
</ion-slides>
</div>
I'm getting the following error:
Unhandled Promise rejection: Template parse errors:
Can't bind to 'slidesPerView' since it isn't a known property of 'ion-slides'.
If 'ion-slides' is an Angular component and it has 'slidesPerView' input, then verify that it is part of this module.
If 'ion-slides' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '#NgModule.schemas' of this component to suppress this message.
("h6 class="slide-title" [innerHTML]="category.name">
][slidesPerView]="3">
<img [src]="product"): MainPage#12:43 ; Zone: ; Task: Promise.then ; Value: ....
can anyone help please.
ionic -v
2.2.1
cordova -v
6.5.0
Recently there was some changes in ion-slides. Make sure you have the latest ionic version (2.0.0).
Also you can use slidesPerView without enclosing it in square brackets as follows
<ion-slides pager loop slidesPerView="3">
<ion-slide>
...
</ion-slide>
<ion-slides>

Possible to add offset to the right of an element in a Zurb Foundation 4 grid?

According to Foundation's docs on the grid component, I can essentially make 1 or more grid columns a space using their offset classes:
<div class="row">
<div class="large-1 columns">1st column</div>
<div class="large-9 large-offset-2 columns">2 spaces to the left of this column</div>
</div>
That will make 1 column, then 2 columns of plain space and the 9 columns. Is it possible to make those offsets to the right of an element instead of the left? For example, something like this?
<div class="row">
<div class="large-1 columns">1st column</div>
<div class="large-9 large-offset-right-2 columns">2 spaces to the right</div>
</div>
Assuming I understand your request correctly, it sounds like you just need to use end instead of offset. For example,
<div class="row">
<div class="large-1 columns a">1st column</div>
<div class="large-9 columns end">2 spaces to the left of this column</div>
</div>