How can I apply different styles to the delivered and pending section lists?
I would like to change the color text of the status data.
Like status data pending Text should be red.
And status data delivered Text should be green.
How can I do this?
or I Should put this data manually? s
Code Bellow:
const delivered = [
{
id: 1,
title: 'Lanche, MADERO',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 2,
title: 'McDonalds',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 3,
title: 'Bobs',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 4,
title: 'Burguer King',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 5,
title: 'Outback',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 6,
title: 'Esfiha',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 7,
title: 'Habibs',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
{
id: 8,
title: 'McDonalds',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Delivered',
},
];
const pending = [
{
id: 1,
title: 'Sushi Garden',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Pending',
},
{
id: 2,
title: 'Gendai Sushi',
description: 'Rua Joao da silva, 22, 12 horas atrás',
status: 'Situação: Pending',
},
];
export default class LastOrders extends Component {
renderItem = ({item}) => (
<TouchableOpacity
onPress={() => {
const {navigation} = this.props;
navigation.navigate('OrderDetail');
}}>
<View style={styles.productContainer}>
<Text style={styles.productTitle}>{item.title}</Text>
<Text style={styles.productDescription}>{item.description}</Text>
<Text style={styles.productStatus}>{item.status}</Text>
</View>
</TouchableOpacity>
);
render() {
return (
<View style={styles.container}>
<SectionList
sections={[
{title: 'Entregas Pendentes', data: pending},
{title: 'Entregas Completas', data: delivered},
]}
renderItem={this.renderItem}
renderSectionHeader={({section}) => (
<View>
<Text style={styles.header}>{section.title}</Text>
</View>
)}
showsVerticalScrollIndicator={false}
keyExtractor={(item) => item.id}
/>
</View>
);
Styles Code Bellow:
import {StyleSheet} from 'react-native';
export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
list: {
padding: 20,
},
productContainer: {
backgroundColor: '#f5f5f5',
borderWidth: 1,
borderColor: '#fff',
borderRadius: 4,
padding: 20,
marginBottom: 20,
},
productTitle: {
fontSize: 18,
fontWeight: 'bold',
color: '#000',
},
productDescription: {
fontSize: 16,
color: '#999',
marginTop: 5,
lineHeight: 24,
},
productStatus: {
fontSize: 16,
color: 'red',
marginTop: 5,
lineHeight: 24,
},
header: {
fontWeight: 'bold',
fontSize: 20,
marginTop: 30,
marginLeft: 20,
},
});
You just have to set the style conditionally.
Your renderItem should be something like below, here I've compared the string directly, if you have some sort of ID for status better compare that.
renderItem = ({ item }) => (
<TouchableOpacity
onPress={() => {
const { navigation } = this.props;
navigation.navigate('OrderDetail');
}}>
<View style={styles.productContainer}>
<Text style={styles.productTitle}>{item.title}</Text>
<Text style={styles.productDescription}>{item.description}</Text>
<Text
style={
item.status === 'Situação: Pending'
? styles.productStatus
: styles.productStatusDelivered
}>
{item.status}
</Text>
</View>
</TouchableOpacity>
);
You will need a new style like this as well
productStatusDelivered: {
fontSize: 16,
color: 'green',
marginTop: 5,
lineHeight: 24,
},
Related
I'm trying to align axis labels in HighCharts
Labels should not be trimed, so ellipsis is not allowed
How it looks now:
How I want it to be:
Code: https://jsfiddle.net/9xw6dL3f/25/
{
"chart": {
"width": 500,
"height": 300,
"type": "column"
},
"title": {
"text": null
},
"xAxis": {
"type": "category",
"labels": {
"rotation": -90,
"style": {
"textOverflow": "none"
}
}
},
"series": [
{
"name": "",
"data": [
{ "name": "Follow me into my theatre of lunacy", "y": -10, "color": "#ABC" },
{ "name": "1", "y": 1, "color": "#000" },
{ "name": "2", "y": 2, "color": "#000" },
{ "name": "3", "y": 3, "color": "#000" },
{ "name": "4", "y": 4, "color": "#000" },
{ "name": "5", "y": 5, "color": "#000" },
]
}
]
}
It is possible to move label depending on it's rows count
Add render function to the chart object
{
"chart": {
...
events: {
render() {
for (let i = 0; i < this.xAxis[0].names.length; i++) {
const label = this.xAxis[0].ticks[i].label;
const rows = (label.element.innerHTML.match(/<\/tspan>/g) || []).length;
label.translate(-8 * rows, 0);
}
}
}
where 8 is half of row size in px
https://jsfiddle.net/kLz1uoga/5/
I'm learning How to use Algolia and I have a few questions.
I have the table FreightDriver, which has a relationship one to many with the table Truck
id: ID!
name: String!
email: String!
phoneNumber: String!
cities: [String!]!
state: String!
country: String!
picture: String
trucks: [Truck] #connection(keyName: "byFreightDriver", fields: ["id"])
Then, the table Truck, which has a relationship one to one with the table FreightDriver, and another table, which is Box one to one as well
id: ID!
freightDriverId: ID!
boxId: ID!
brand: String!
model: String!
yearModel: Int!
// and more fields
freightDriver: FreightDriver #connection(fields: ["freightDriverId"])
box: Box #connection(fields: ["boxId"])
and the table Box:
id: ID!
type: String!
width: Float!
height: Float!
depth: Float!
I want to find trucks based on the state and city of the FreightDrivers, and also (if the user needs it), find based on the type of box and brand or model of a truck (just as an example).
Example find by state and city of a FreightDriver:
{
"data": {
"freightDriversByState": {
"items": [
{
"name": "Andrés Montoya",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Ganadera",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Volcadora",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "hola",
"model": "12",
"yearModel": 12,
"box": {
"type": "Plataforma",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 1
}
},
{
"brand": "dasdas",
"model": "12",
"yearModel": 12231,
"box": {
"type": "Grúa",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Tesla",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 4,
"height": 4,
"depth": 2
}
}
]
}
},
{
"name": "Roberto mendez",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": []
}
},
{
"name": "Fletes Jalisco Sa de Cv ",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.5,
"depth": 4.5
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2009,
"box": {
"type": "Seca (abierta)",
"width": 2.3,
"height": 2,
"depth": 4
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 2.35,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2004,
"box": {
"type": "Seca (abierta)",
"width": 2.5,
"height": 2,
"depth": 3
}
}
]
}
},
{
"name": "Cotransport",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Chevrolet",
"model": "CX-5",
"yearModel": 2019,
"box": {
"type": "Seca (cerrada)",
"width": 4,
"height": 3,
"depth": 4
}
}
]
}
},
{
"name": "Andrés",
"cities": [
"EL LIMÓN",
"MAGDALENA",
"SANTA MARÍA DEL ORO",
"GUADALAJARA",
"ETZATLÁN"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
}
]
}
}
]
}
}
}
But, if I want to find using the state and city of a freight driver, the type of box and the model or brand of a truck, that's where the problem comes, because I'm using Dynamodb and this one does not have relationships, so, it's a little bit tricky to get the exact data. That's why I'd like to use Algolia, but how do I format the data for Algolia in this case? What do I need to do? thanks!
If someone is interested, here's the answer https://discourse.algolia.com/t/how-to-format-data-to-algolia/10897
Sample Code
JsFiddle Example for below code.
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares in January, 2018'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [
{
"name": "Display",
"y": 0.1,
"value": 5
},
{
"name": "Paid Social",
"y": 0,
"value": 0,
sliced: true,
selected: true
},
{
"name": "Direct",
"y": 14.5,
"value": 559
},
{
"name": "Referral",
"y": 2,
"value": 77
},
{
"name": "Email",
"y": 4,
"value": 152
},
{
"name": "Other",
"y": 0,
"value": 1
},
{
"name": "Organic Search",
"y": 23.4,
"value": 901
},
{
"name": "Meta Search",
"y": 0.2,
"value": 5
},
{
"name": "Organic Social",
"y": 2.4,
"value": 93
},
{
"name": "Directory",
"y": 0.2,
"value": 9
},
{
"name": "Other Advertising",
"y": 0.1,
"value": 3
},
{
"name": "OTA Referral Traffic",
"y": 0.7,
"value": 26
},
{
"name": "Paid Search",
"y": 27.8,
"value": 1068
},
{
"name": "Local",
"y": 24.5,
"value": 941
}]
}]
});
Scenario
I want to display dataLabels for all even y value is zero.
In Above code We have "name": "Display" y=0.1 but still it is not displaying in Pie Chart don't know why. If any one have idea about this problem please let me know.
The dataLabels are hidden due to lack of space and overlapping. As a solution you can set: padding: 0
plotOptions: {
pie: {
...,
dataLabels: {
padding: 0,
...
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/g5s27tyb/
API Reference: https://api.highcharts.com/highcharts/plotOptions.pie.dataLabels.padding
browser: Chrome 60.0.3112.78
Original:
CSSRuleList {0: CSSStyleRule, 1: CSSStyleRule, 2: CSSStyleRule, 3: CSSStyleRule, length: 4}
length:4
0:CSSStyleRule {selectorText: ".highlight", style: CSSStyleDeclaration, type: 1, cssText: ".highlight { background-color: rgb(182, 246, 156); }", parentRule: null, …}
1:CSSStyleRule {selectorText: ".highlight:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlight:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
2:CSSStyleRule {selectorText: ".highlightb6f69c:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
3:CSSStyleRule {selectorText: ".highlightb6f69c", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c { background-color: rgb(182, 246, 156); }", parentRule: null, …}
Operation:
> document.getElementById('styles').sheet.removeRule('.highlightb6f69c')
<- undefined
> document.getElementById('styles').sheet.rules
<- CSSRuleList {0: CSSStyleRule, 1: CSSStyleRule, 2: CSSStyleRule, 3: CSSStyleRule, length: 3}
length:3
0:CSSStyleRule {selectorText: ".highlight:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlight:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
1:CSSStyleRule {selectorText: ".highlightb6f69c:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
2:CSSStyleRule {selectorText: ".highlightb6f69c", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c { background-color: rgb(182, 246, 156); }", parentRule: null, …}
I want to remove the class .highlightb6f69c, but Chrome remove .highlight instead, why?
The screenshot
From https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/deleteRule
The CSSStyleSheet.deleteRule() method removes a style rule from the current style sheet object.
Syntax
stylesheet.deleteRule(index)
Parameters
index is a long number representing the position of the rule.
So, the reason the wrong rule is removed is because of .highlightb6f69c is parsed as 0 or NaN, removing the first one.
I have created jqGrid in which i have to give color on row select but when i am trying to give for even rows, it's working fine but for odds rows it's not working.
I don't want to use jQuery or JavaScript i just want to do it from CSS. Is there way to achieve it?
Below is my sample code which is working for even rows:
.ui-jqgrid .ui-state-highlight:nth-child(even) { background: #d0e5f5; }
For odd rows its not working:
.ui-jqgrid .ui-state-highlight:nth-child(odd) { background: #d0e5f5; }
Sorry, but all works without any problem at me. Press "Run code snippet" button below and highlight odd or even rows on the demo
$(function () {
"use strict";
var mydata = [
{ id: "1", invdate: "2007-10-21", name: "test", note: "3note note note", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
{ id: "2", invdate: "2007-10-22", name: "test2", note: "3note2 note2", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
{ id: "3", invdate: "2007-09-01", name: "test3", note: "3note3 note3", amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
{ id: "4", invdate: "2007-10-14", name: "test4", note: "3note4", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
{ id: "5", invdate: "2007-10-31", name: "test5", note: "3note5", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
{ id: "6", invdate: "2007-09-06", name: "test6", note: "3note6", amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
{ id: "7", invdate: "2007-10-04", name: "test7", note: "3note7", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
{ id: "8", invdate: "2007-10-03", name: "test8", note: "3note8", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
{ id: "9", invdate: "2007-09-22", name: "test9 test9 test9 test9 test9", note: "3note9", amount: "400.00", tax: "30.00", closed: false, ship_via: "TN", total: "430.00" },
{ id: "10", invdate: "2007-09-08", name: "test10", note: "3note10", amount: "500.00", tax: "30.00", closed: true, ship_via: "TN", total: "530.00" },
{ id: "11", invdate: "2007-09-28", name: "test11", note: "3note11", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" },
{ id: "12", invdate: "2007-09-10", name: "test12", note: "3note12", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" }
],
initDatepicker = function (elem) {
$(elem).datepicker({
autoSize: true,
changeYear: true,
changeMonth: true,
showButtonPanel: true,
showWeek: true
});
},
numberTemplate = {formatter: "number", align: "right", sorttype: "number",
editrules: {number: true, required: true},
searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge", "nu", "nn", "in", "ni"] }},
$grid = $("#list");
$grid.jqGrid({
datatype: "local",
data: mydata,
colNames: ["Client", "Date", "Amount", "Tax", "Total", "Closed", "Shipped via", "Notes"],
colModel: [
{ name: "name", editrules: {required: true} },
{ name: "invdate", align: "center", sorttype: "date",
formatter: "date",
searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"], dataInit: initDatepicker } },
{ name: "amount", template: numberTemplate },
{ name: "tax", template: numberTemplate },
{ name: "total", template: numberTemplate },
{name: "closed", align: "center", formatter: "checkbox",
edittype: "checkbox", editoptions: {value: "Yes:No", defaultValue: "Yes"},
stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;true:Yes;false:No" } },
{name: "ship_via", align: "center", formatter: "select",
edittype: "select", editoptions: { value: "FE:FedEx;TN:TNT;IN:Intim", defaultValue: "FE" },
stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;FE:FedEx;TN:TNT;IN:Intim" } },
{ name: "note", sortable: false, search: false, edittype: "textarea" }
],
rowNum: 10,
rowList: [5, 10, 20],
pager: "#pager",
gridview: true,
rownumbers: true,
autoencode: true,
ignoreCase: true,
sortname: "invdate",
viewrecords: true,
sortorder: "desc",
shrinkToFit: false,
height: "auto"
});
});
.ui-jqgrid-hdiv { overflow-y: hidden; }
.ui-jqgrid .ui-state-highlight:nth-child(even) { background: #CCCCFF; }
.ui-jqgrid .ui-state-highlight:nth-child(odd) { background: #B2EC5D; }
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/css/ui.jqgrid.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/jquery.jqGrid.src.js"></script>
<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>