Some of my datatable column shows as number datatype in excel how to prevent it defined as number without comma delimiter - excel

I have 4 columns in datatables and wanted to export into xlsx file 2 of the column, one column is name and phone, but after export, one of the column (phone) will show millions as 1,000,000 for example. I wish that phone number column to be treated as text but failed many times
This is my code and loading the data from json text using php
$(document).ready(function()
{
$('#example').DataTable( {
"ajax": "json.php",
"pageLength": 100,
"deferRender": true,
dom: 'Bfrtip',
lengthMenu: [
[ 10, 25, 50, 100, 200, 500, 1000],
[ '10 rows', '25 rows', '50 rows', '100 rows', '200 rows' , '500 rows', '1000 rows']
],
buttons: ['pageLength','copy',
{extend: 'excelHtml5',
filename: 'export',
title: null,
exportOptions: {
columns: [ 1, 2 ],
format: {
body: function (data, row, column, node )
{
return column === 2 ? "\0" + data : data;
//return column === 2 ? = & "" + data : data;
}
},
}
}
],
} );
} );

Related

Set a formated date cell for Google sheet api with nodeJS

I'm trying to update my google sheet by inserting a date. I want to have different format for different cells.
Using nodeJS api I have a class Sheet with is used in another class SpreadSheet witch contains the spreadsheet info to make batchupdates
import {sheets_v4} from "googleapis";
type DatePattern = "dd-mm-yyyy" | "hh:mm:ss" | "dd-mm-yyyy hh:mm:ss" | string
type DateType = "DATE" | "TIME" | "DATE_TIME"
export class Sheet {
private request: sheets_v4.Schema$Request[] = []
/**
*
* #param columnIndex {number} Index of the column (Starting from 0)
* #param rowIndex {number} Index of the row (Starting from 0)
* #param value {string}
*/
setPercentFormula(columnIndex: number, rowIndex: number, value: string) {
this.request.push({
updateCells: {
fields: 'userEnteredValue,userEnteredFormat',
range: {
sheetId: this.sheetId,
startColumnIndex: columnIndex,
endColumnIndex: columnIndex + 1,
startRowIndex: rowIndex,
endRowIndex: rowIndex + 1,
},
rows: [
{
values: [
{
userEnteredValue: {
formulaValue: value
},
userEnteredFormat: {
numberFormat: {
type: "PERCENT",
pattern: "#0.00%;-#0.00%;0%"
}
}
},
]
},
]
}
})
return this
}
/**
*
* #param columnIndex {number} Index of the column (Starting from 0)
* #param rowIndex {number} Index of the row (Starting from 0)
* #param value {string}
* #param type {DateType}
* #param pattern {DatePattern} Pattern format
*/
setDateWithPatternCell(columnIndex: number, rowIndex: number, value: string, type: DateType, pattern: DatePattern) {
this.request.push({
updateCells: {
fields: 'userEnteredValue,userEnteredFormat',
range: {
sheetId: this.sheetId,
startColumnIndex: columnIndex,
endColumnIndex: columnIndex + 1,
startRowIndex: rowIndex,
endRowIndex: rowIndex + 1,
},
rows: [
{
values: [
{
userEnteredValue: {
stringValue: value,
},
userEnteredFormat: {
numberFormat: {
type: type,
pattern: pattern
}
}
},
]
},
]
}
})
return this
}
}
I have other utility function, for boolean value or formula for example. All of they put the actions in the request array, then this array is use in batchUpdate call.
For example, the use of setPercentFormula work perfectly well.
The result in my sheet is a cell with a starting coma and then the date as string given in the value parameter of my function.
It looks like my formatting isn't accounted.
As it is a number format, I also tried to use userEnteredValue: { numberValue: value } and give it a timestamp as input but resulting in setting the number in the cell and no date.
I also tried to make to separate call by putting two value in my request array. One setting the string and another one setting the formatting. with the same result.
I would like as a result to have my sheet with my date value as if I manually got in the file and clicked Format > Number > Date for example. Without the starting coma and a value recognized as a date.
Here are some input I tried :
Sheet.setDateWithPatternCell(0, 0, '2022-08-10', 'DATE', 'yyyy-mm-dd')
Sheet.setDateWithPatternCell(0, 0, Date.now(), 'DATE', 'yyyy-mm-dd')
Sheet.setDateWithPatternCell(0, 0, Date.now(), 'DATE_TIME', 'yyyy-mm-dd hh:mm:ss')
I expect the output in my google sheet to be the date with the format is specified.
Not the string (as I see in my sheet it's starting with a ' in the value)
I believe your goal is as follows.
You want to put a date object to a cell with your expected format using Sheets API.
Unfortunately, from your question, I couldn't find your tested values of columnIndex, rowIndex, value, type, pattern. So, in this answer, I would like to propose a sample request body for achieving your goal.
When "updateCells" request with the method of spreadsheets.batchUpdate is used, and a sample request body is as follows.
Sample request body:
{
"requests": [
{
"updateCells": {
"fields": "userEnteredValue,userEnteredFormat",
"range": {
"sheetId": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"startRowIndex": 0,
"endRowIndex": 1
},
"rows": [
{
"values": [
{
"userEnteredValue": {
"numberValue": 44803
},
"userEnteredFormat": {
"numberFormat": {
"type": "DATE_TIME",
"pattern": "dd-mm-yyyy hh:mm:ss"
}
}
}
]
}
]
}
}
]
}
44803 is the serial number. Please be careful about this.
When this request body is used with the method of spreadsheets.batchUpdate, 30-08-2022 00:00:00 is put into the cell "A1" of sheet ID of 0 as the date object.
For example, when the pattern, type and value are dd-mm-yyyy, DATE, and 44803, respectively, 30-08-2022 is put to the cell.
As another approach, when the method of spreadsheets.values.update is used, you can also the following script. In this case, 30-08-2022 00:00:00 is put to the cell "A1" of "Sheet1" as the date object.
sheets.spreadsheets.values.update({
spreadsheetId: "###", // Please set your Spreadsheet ID.
range: "Sheet1!A1",
valueInputOption: "USER_ENTERED",
resource: { values: [["30-08-2022 00:00:00"]] },
});
References:
Method: spreadsheets.batchUpdate
Method: spreadsheets.values.update

Vertical lines in pdfkit-tables in node.js

I have API that generate pdf file after saving values into database. My customer needed to generate this pdf and then send it by mail. He sended my photo of how should that pdf look like. I recreated it, it looks same as in that picture but it is hard to read because there are missing vertical lines. I looked trought docs and also tried to google, bud I did not found anyithing.
Here is how my PDF looks like:
As you can see, vertical lines are missing and because of that is harder to read.
Is there any possibility to add vertical lines?
Here is my code:
let doc = new PDFDocument({ margin: 30, size: "A4" });
doc.pipe(
fs.createWriteStream(`${problemName}_${creationDate}` + ".pdf")
);
const table = {
title:
"Zápis koordinátora " +
koordinatorName +
" zo dna " +
creationDate +
".",
divider: {
header: { disabled: true },
horizontal: { disabled: false, width: 1, opacity: 1 },
padding: 5,
columnSpacing: 10,
},
headers: [
{ width: 130, renderer: null },
{ width: 130, renderer: null },
{ width: 130, renderer: null },
{ width: 130, renderer: null },
],
rows: [
["Nazov", problemName, "", ""],
[
"Nazov staveniska (Projekt)",
constructionName,
"Na vedomie komu",
"mailing list 1",
],
[
"Vytvoril koordinator BOZP",
koordinatorName,
"Priorita",
problemPriority,
],
["Datum zistenia", creationDate, "Datum odstranenia", ""],
[
"Zodpovedny za vyriesenie zistenia",
"Janko Maly",
"Celkovy pocet zisteni v dni",
10,
],
["Miesto zistenia", discoveryPlace, "Zistenie císlo", 1],
["Popis", problemText],
[
"Navrh na udelenie sankcie",
"50€",
"Pre spolocnost",
adressedFor,
],
],
};
doc.table(table, {
prepareHeader: () => doc.font("Helvetica-Bold").fontSize(8),
prepareRow: (row, indexColumn, indexRow, rectRow, rectCell) => {
doc.font("Helvetica").fontSize(8);
indexColumn === 0;
},
});
doc.end();
I am using pdfkit-table package.
Thank you all
By definition simple PDF structure is not tabular there is one cell (the page) and that one column can be subdivide into two or more rows with null spaces between the text sub columns.
That is why tables are difficult to sub[ex]tract
So adding coloured rows in one area is fairly simple to make like a table, thus to make vertical sub dividers is more difficult, However that feature was added in January 2022 https://github.com/natancabral/pdfkit-table/files/7865078/document-5.pdf
For exsample see https://github.com/natancabral/pdfkit-table/issues/16#issuecomment-1012389097

How to sum the values of a JQgrid footer row when the value is already in linked

I have this code that needs to be display the total sum of few columns, The JQgrid works fine in normal column value. But when that column value is linked, It shows Nan
grid.jqGrid({
data: mydata,
datatype: "local",
height: containerHeight,
width: containerWidth,
colNames:[
//'Region/Purchaser Name',
'Order No. / Invoice No.','PO No.','Ship To','Ship To Attention','Address','City','State / Zip','Requested Ship Date','Shipped Date','Total Qty Ordered','Shipped to WF','Open Qty'],
colModel:[
//{name:'REGION',index:'REGION', width:20},
{name:'DUMMYMACNO',index:'MACNO', width:19, align:"center"},
{name:'PONUM',index:'PONUM', width:17},
{name:'SHIPTO',index:'SHIPTO', width:17},
{name:'ATTN',index:'ATTN', width:19,align:"center",formatter:nullFormatter},
{name:'ADDRESS',index:'ADDRESS', width:19},
{name:'CITYJ1',index:'CITYJ1', width:10},
{name:'STZIP',index:'STZIP', width:10},
{name:'SDATE',index:'SDATE', width:10},
{name:'INVDATE',index:'INVDATE', width:10},
{name:'TQO',index:'TQO', width:4, align:"center"},
{name:'DQTY',index:'DQTY', width:5, search:false, align:"center", sorttype:"float", formatter:function(cellvalue, options, rowObject){return ''+cellvalue+'';},classes: 'blue-text'},
{name:'OQO',index:'OQO', width:6, search:false, align:"center", sorttype:"float", formatter:function(cellvalue, options, rowObject){return ''+cellvalue+'';}},
],
rowNum:100,
rowList : [100,150,200],
loadonce:true,
mtype: "GET",
casesensitive: true,
rownumbers: true,
rownumWidth: 40,
ignoreCase: true,
gridview: true,
pager: '#locationlistpagination',
sortname: 'SONO',
viewrecords: true,
loadComplete: function() {
$("tr.jqgrow:odd").addClass('jqgrow-alt-row');
},
sortorder: "asc",
footerrow: true,
gridComplete: function() {
var colsum = 0;
var colsum1 = 0;
var colSum2 = 'Total';
var colSum4 = 'Total';
var colSum = grid.jqGrid('getCol', 'DQTY', true, 'sum');
var colSum4 = grid.jqGrid('getCol', 'OQO', true, 'sum');
var colSum1 = grid.jqGrid('getCol', 'TQO', false, 'sum');
grid.jqGrid('footerData', 'set', { OQO: colSum });
grid.jqGrid('footerData', 'set', { DQTY: colSum4 });
grid.jqGrid('footerData', 'set', { TQO: colSum1 });
grid.jqGrid('footerData', 'set', { SDATE : colSum2 });;
}
})
The query works fine in ColSum1 and colSum2, but its shows Nan in ColSum and Colsum4. Can any one have a way to solve this
The getCol method sum a values which are numbers in grid, after they are formatted from the formatter. The values where you get NaN are not numbers, but links after formatting. In order this to work correctly you should define a unformat function which will convert back the link to a number. See the Guriddo docs here

Calculating total amount from nouisliders

I want the amount of two noUiSliders to autoupdate as I slide and be displayed at the Sum.
The value from the first slider to be multiplied with the value from the second slider, then multiply that again by 110. The result will then display in the span sum.
<h2>Antall selgere <span id="selgere"></span></h2>
<div class="slide_selgere"></div>
<h2>Antall pakker <span id="pakker"></span></h2>
<div class="slide_pakker"></div>
Sum: <span id="sum"></span>
My script is as follows:
$(".slide_selgere").noUiSlider({
start: [ 5 ],
step: 1,
format: wNumb({
decimals: 0
}),
range: {
'min': [ 1 ],
'max': [ 10 ]
}
});
$(".slide_selgere").Link('lower').to($('#selgere'));
$(".slide_pakker").noUiSlider({
start: [ 15 ],
step: 1,
format: wNumb({
decimals: 0
}),
range: {
'min': [ 1 ],
'max': [ 100 ]
}
});
$(".slide_pakker").Link('lower').to($('#pakker'));
Use another .Link() on both sliders:
var sliders = $('.slider'), sum = $('#sum');
sliders.Link().to(function( value ){
// Use .not() to filter the sliders, finding the one that *didn't* change.
var total = Number(value) + Number(sliders.not($(this)).val());
sum.html(total);
});
See a live example here.

YUI paginator infinity records in table

I am using YUI for displaying data.
This row is used for set count of records per page:
rowsPerPageOptions : [ 10, 25, 50, 100 ]
Does it have ability to set infinity number of records?
Try just [ 20, 50, 100, 250, 500, 1000, 'all' ]
Resolved using custom page count names and max int.
rowsPerPageOptions : [
{ value : 20, text : '20' },
{ value : 50, text : '50' },
{ value : 100, text : '100' },
{ value : 250, text : '250' },
{ value : 500, text : '500' },
{ value : 1000, text : '1000' },
{ value : 9007199254740992, text : 'All' }],

Resources