There aren't any vanilla examples on creating a datatable for Svelte. I've found a couple examples that I'm trying to learn from, but still a no go. Right now I'm trying to build it on the REPL tab and in the results tab I get my two rows but all three fields are the same, instead unique like I'm expecting.
I've tried [], slice, concating, each per row, and probably some others I can't think of right now.
<script>
import { beforeUpdate, createEventDispatcher, onMount } from 'svelte';
export let faketable = [{Color:'BLUE', Car:'Camaro', Brand:'Chevy'},{Color:'RED', Car:'Pinto', Brand:'Ford'}];
export let columns = ["Color", "Car", "Brand"];
export let rows = ['blue','Camaro','Chevy'];
//export let try1 = JSON.parse(faketable);
export let clickable = true
const dispatch = createEventDispatcher();
export function click(row) {
if (!clickable) {
return;
}
if (getSelection().toString()) {
// Return if some text is selected instead of firing the row-click event.
return;
}
dispatch('row-click', row);
// console.log('click', row);
}
</script>
<div>
<h3 class="panel-title">Please work!</h3>
<table ref="table" class="table table-striped table-hover" style="width:100%">
<thead>
<tr>
{#each columns as column, x}
<th style="width: { column.width ? column.width : 'auto' }" align="center">
{column}
</th>
{/each}
</tr>
</thead>
<tbody>
{#each faketable as row, y}
<tr class="{ clickable ? 'clickable' : '' }" on:click="{() => click(row)}">
{#each columns as column, x}
<td align="center">
{row.Color}
</td>
{/each}
</tr>
{/each}
</tbody>
</table>
</div>
<style>
tr.clickable {
cursor: pointer;
}
table {
table-layout: fixed;
}
table tr td {
padding: 0 0 0 56px;
height: 48px;
font-size: 13px;
color: rgba(0, 0, 0, 0.87);
border-bottom: solid 1px #DDDDDD;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
table th {
border-radius: 0;
}
table tbody tr:hover {
background-color: #EEE;
}
</style>
The headers look like I want them to be Color, Car, & Brand. But each row I expect faketable to return Blue Camaro Chevy then Red Pinto Ford, respectively.
You have {row.Color} where you should have {row[column]}. Fix that, and it works
Related
I am working with pdf-reactor and cannot make the header and footer to be in every page. I can, if I have only those two elements, header and footer, they are showing, but soon as I enter a single letter, footer disappears.
<div class="header">
<table class="header header-footer">
<tr>
<td class="invoicetext">header</td>
</tr>
</table>
</div>
<div class="footer">
<table class="footer header-footer">
<tr>
<td class="pagecounter">footer1</td>
</tr>
</table>
</div>
And this is the css:
#page {
margin: 2cm 2.5cm 3cm 2.5cm;
#top-left {
content: element(headerIdentifier);
vertical-align: bottom;
}
#bottom-left {
content: element(footerIdentifier);
vertical-align: top;
width: 100%;
}
#bottom-right {
content: element(companyIdentifier);
vertical-align: top;
margin-top: 4mm;
width: 100%;
}
}
div.spacing {
margin-top: 1.2em;
}
div.footer, div.header {
font: 9pt arial, sans-serif;
width: 100%;
}
div.footer {
position: running(footerIdentifier);
}
div.header {
position: running(headerIdentifier);
}
No matter where I add another div, on the top, bottom, between the header and footer, footer just disappears. How to prevent this from happening.
We can reproduce this behavior here (issue #7827 in our internal tracking system). It seems to only occur when the running elements contain tables and when they are followed by only inline elements or text.
As a workaround, you could wrap the content after the running elements in a block element like this:
<div class="header">
...
</div>
<div class="footer">
...
</div>
<p>Some Text</p>
I am trying to build a .net core project that will use the google places api to autocomplete an address. To test the process I copied the demo code from google and put it in the .net core template generated by visual studio 2017. The autocomplete doesn't work, but if I change the .cshtml to .html and navigate to it manually it works fine.
<!DOCTYPE html>
<html>
<head>
<title>Place Autocomplete Address Form</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<style>
#locationField, #controls {
position: relative;
width: 480px;
}
#autocomplete {
position: absolute;
top: 0px;
left: 0px;
width: 99%;
}
.label {
text-align: right;
font-weight: bold;
width: 100px;
color: #303030;
}
#address {
border: 1px solid #000090;
background-color: #f0f0ff;
width: 480px;
padding-right: 2px;
}
#address td {
font-size: 10pt;
}
.field {
width: 99%;
}
.slimField {
width: 80px;
}
.wideField {
width: 200px;
}
#locationField {
height: 20px;
margin-bottom: 2px;
}
</style>
</head>
<body>
<br />
<br />
<br />
<br />
<div id="locationField">
<input id="autocomplete" placeholder="Enter your address"
onFocus="geolocate()" type="text"></input>
</div>
<table id="address">
<tr>
<td class="label">Street address</td>
<td class="slimField">
<input class="field" id="street_number"
disabled="true"></input>
</td>
<td class="wideField" colspan="2">
<input class="field" id="route"
disabled="true"></input>
</td>
</tr>
<tr>
<td class="label">City</td>
<!-- Note: Selection of address components in this example is typical.
You may need to adjust it for the locations relevant to your app. See
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
-->
<td class="wideField" colspan="3">
<input class="field" id="locality"
disabled="true"></input>
</td>
</tr>
<tr>
<td class="label">State</td>
<td class="slimField">
<input class="field"
id="administrative_area_level_1" disabled="true"></input>
</td>
<td class="label">Zip code</td>
<td class="wideField">
<input class="field" id="postal_code"
disabled="true"></input>
</td>
</tr>
<tr>
<td class="label">Country</td>
<td class="wideField" colspan="3">
<input class="field"
id="country" disabled="true"></input>
</td>
</tr>
</table>
<script>
// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')),
{ types: ['geocode'] });
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=MYAPIKeythat works in html&libraries=places&callback=initAutocomplete"
async defer></script>
</body>
</html>
This issue was that the wrong API was activated on google. I enabled it in google and it works in the project now. I have no idea why it worked in the plain html.
I am trying to create a PDF that contains table which is partly filled, partly empty. To accomplish this I am using DomPDF via a Laravel wrapper.
It seems that DomPDF somehow miscalculates the height of the empty cells and also displaces the table grid and content.
Here is a minimal broken example:
<html>
<head>
<style>
html, body {
font-family: DejaVu Sans;
}
table {
border-collapse: collapse;
border: none;
margin: 0;
width: 100%;
}
table.main td {
padding: 0;
border: 2px solid black;
}
.main table td {
border: 1px black solid;
text-align: center;
font-size: 10px;
height: 14px;
}
</style>
</head>
<body>
<table class="main">
<tr>
<td>
<table>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
<tr><td>10</td></tr>
</table>
</td>
<td>
<table>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
This is how that table looks like in the generated PDF:
I have tried to add min-height and max-height for the table cell, but no results, it still randomly misaligns everything.
It turns out that this requires line-height to be set exactly equal to the font size. This will work:
.main table td {
border: 1px black solid;
text-align: center;
font-size: 10px;
line-height: 10px;
height: 14px;
}
I create an Invoice. Where I put 3 fields: Quantity, Rate and Total Amount. Total amount calculate following this format (Quantity*Rate). All total Amount Sum Show on Sub_total div. Here is my code:
<html>
<head>
<title>Invoice</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".qty").each(function() {
$(this).keyup(function(){
calculateSum();
});
});
$(".rate").each(function() {
$(this).keyup(function(){
calculateSum();
});
});
});
function calculateSum() {
var qty = 1;
$(".qty").each(function() {
if(!isNaN(this.value) && this.value.length!=0) {
qty = parseFloat(this.value);
}
});
var rate = 0;
$(".rate").each(function() {
if(!isNaN(this.value) && this.value.length!=0) {
rate = parseFloat(this.value);
}
});
$('input[name=total_amount]').val(qty.toFixed(2)*rate.toFixed(2));
}
</script>
<style type="text/css">
table
{
border: 1px solid black;
border-bottom: none;
width: 600px;
}
td
{
border-left: 1px solid black;
border-bottom: 1px solid black;
padding:5px 5px 5px 5px;
}
#first
{
border-left: none;
border-bottom: 1px solid black;
}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td id="first">Quantity</td>
<td>Rate</td>
<td>Total Amount</td>
</tr>
<?php
$num=4;
for ($i=0; $i<$num; $i++)
{
echo "
<tr>
<td id='first'><input class='qty' type='text' name='qty[]'/></td>
<td><input class='rate' type='text' name='rate[]'/></td>
<td><input class='total_amount' type='text' name='total_amount[]'/></td>
</tr>";
}
?>
<tr>
<td id="first" colspan="2" align="right">Sub Total:</td>
<td><span id="sub_total">0</span></td>
</tr>
</table>
</body>
</html>
I want to show each Total amount following this way
total_amount[1]=(qty[1]*rate[1])
total_amount[2]=(qty[1]*rate[1])
total_amount[3]=(qty[1]*rate[1])
total_amount[4]=(qty[1]*rate[1])
I am trying so hard but my codes don’t work properly. So pls pls pls some one help me to solve this problem.
$(document).ready(function(){
$(".qty, .rate").keyup(function(){
calculateSum();
});
});
function calculateSum() {
var qty = [];
$(".qty").each(function() {
var num = parseFloat(this.value) || 1;
qty.push(num);
});
var rate = [];
$(".rate").each(function() {
var num = parseFloat(this.value) || 0;
rate.push(num);
});
var sub_total = 0;
$('input[name=total_amount]').each(function(i){
var amount = qty[i].toFixed(2)*rate[i].toFixed(2);
total += amount;
$(this).val(amount);
}
$("#sub_total").text(total);
}
You don't need to assign the events using $.each in the first place..
$('.qty , .rate').keyup(function() {
calculateSum($(this).closest('tr'));
});
function calculateSum($tr) {
var $qty = $tr.find('.qty').val();
var $rate = $tr.find('.rate').val();
$tr.find('.total_amount').val( parseFloat($qty).toFixed(2)* parseFloat($rate).toFixed(2) )
}
This should be sufficient
The IE8 documentation says it supports min-width, but it doesn't seem to work for me.
The html I want to be a minimum width is in table cells.
I saw another question here which suggested adding a 1-pixel height div to each cell, with a width setting, but that doesn't work - IE renders it as 18 pixels high, for some reason.
Here is the html code:
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<style type="text/css">
table.keyboard div.key {
height: 50px;
font-size:50px;
border: 5px outset gray;
min-width: 60px;
text-align: center;
}
table.keyboard div.spc {
height: 1px;
width: 60px;
background-color: green;
}
table.keyboard td:hover {
background-color: lightblue;
}
table.keyboard {
border: 3px inset blue;
}
</style>
</head>
<body>
<div id="body">
<div>Here is some stuff</div>
<table class='keyboard'>
<tbody>
<tr>
<td><div class='key'>1</div><div class='spc'></div></td>
<td><div class='key'>2</div><div class='spc'></div></td>
<td><div class='key'>3</div><div class='spc'></div></td>
<td><div class='key'>4</div><div class='spc'></div></td>
<td><div class='key'>5</div><div class='spc'></div></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
The "spc" div appears 18 px high!
Of course, if min-width worked, I wouldn't need the div...
<table class='keyboard'>
<tbody>
<tr>
<td><div class='key'>1</div></td>
<td><div class='key'>2</div></td>
<td><div class='key'>3</div></td>
<td><div class='key'>4</div></td>
<td><div class='key'>5</div></td>
</tr>
</tbody>
</table>
Any clues?
Just to make this easier, I have put 3 different versions of this code on my website.
http://jsfiddle.net/3htmA/
IE8. your code works perfect.
The HTML TABLE spec uses COL to define column widths. See the following spec: http://www.w3.org/TR/html4/struct/tables.html#h-11.2.4
Here's an example of how it's used:
http://www.htmldog.com/guides/htmladvanced/tables/
Min-width on table cells works differently than block-level elements. Table cells are controlled on the column level, not on the individual cell level. If a given cell size increases or decreases, the entire column will be affected, unless explicitly controlled by the tag.
Try this:
table.keyboard .key
{
min-width:60px;
width: expression(this.width < 60 ? 60: true);
}
This width expressions is an alternative for min-width, it supposed to be a workaround for older versions of IE.
I think your problem is that your column is determining the width of the element, not the div.
EDIT:
Also check if your browser is not in Compatibility mode.