Format a tabulator.js cell based on another value - tabulator

I would like to color the cell value (Amount) in green only if the value of (KP) is true by maintaining the original money formatting.
This is my actual definition of my 2 relevant columns:
{ title: "Amount", field: "amount", width: 60, sorter: "number", hozAlign: "right", headerSort: false, formatter: "money", formatterParams: {thousand: " ", precision: 0 }, bottomCalc: "sum", bottomCalcFormatter: "money", bottomCalcFormatterParams: {thousand: " ", precision: 0}},
{ title: "KP", field: "cache", width: 25, hozAlign: "center", formatter: "tickCross",
headerSort: false, headerFilter: true, headerFilterParams: { tristate: true } },
The example shown on the webpage obviously does not work for me as I need to refer to another cell and I want to keep the predefined formatter and formatterParams options

You can use a custom function in the formatter, this example from the documentation.
{title:"Name", field:"name", formatter:function(cell, formatterParams, onRendered){
//cell - the cell component
//formatterParams - parameters set for the column
//onRendered - function to call when the formatter has been rendered
return "Mr" + cell.getValue(); //return the contents of the cell
}
It wouldn't be difficult to emulate the money formatter return value, this would be the best approach in my view. Alternatively if you wanted to run a second formatter function following the inbuilt tabulator "money" formatter you could do this by setting the cell element style, something like cell.style.fillColor = rgb etc has worked for me before. I find the first approach far better however.
Refer the documentation here Tabulator Formatters

Related

Tabulator and send data to C#

When using tabulator-tables#4.9.3
Created 2 drop down list columns with editor: "select"
Used Code:
{title: "ProductID", field: "productID", sorter: "string", minWidth: 100, width: 150, sorter: "number", editable: Editable, editor: "number", validator: "required", hozAlign: "left", editor: "select", editorParams: { values: ProductIDSelect }, formatter: "lookup" , formatterParams: ProductIDSelect },
For Example: Products and Units. This type of drop down contain Name, ID.
After choose the name and press on save button will send the data from tabulator to C# to check all data type and Inserted to the table in database Image below.
enter image description here
Before sanded data I check data array with press right click on the page choose "Inspect" getting the below image
enter image description here
Shares indicate the number between "4" and "5" string type
When matching data by C# and finds that the Integer field type and string data are incorrect

Tabulator, Repeat column at bottom of table

I have a column defined as below
{
title: "Actual",
field: "actual_fee",
width: 110,
hozAlign: "right",
formatter: "money",
formatterParams: {
decimal: ".",
thousand: ",",
symbol: "£",
precision: 0
},
bottomCalc: "sum",
bottomCalcFormatter: "money",
bottomCalcFormatterParams: {
decimal: ".",
thousand: ",",
symbol: "£",
precision: 0
}
},
I would like to repeat the column header at the bottom of the table also. Is this possible?
I am using a bottomCalc, so cannot use a custom formatter to do it
Thanks
Tabulator does not have the option to duplicate the column header, it is only available at the top of the table

Why is Tabulator textarea losing focus on every key press?

I have a simple Tablulator JS Fiddle at the link below that has 3 columns. The last column (TA Test) has both the formatter and editor set to 'textarea'. Any attempt to enter values into that field result in the cell immediately losing focus on any key press (at least I think that is what is happening). There are no console or other errors and from what I can tell all the Tabulator options are correct.
What am I missing here to make this cell editable as a textarea?
https://jsfiddle.net/gbvam5ck/2
var data = [
{
pid: 1001,
title: "Test One",
Q1: {qid: 1, value: 1},
Q2: {qid: 2, value: null},
},
{
pid: 1002,
title: "Test Two",
Q1: {qid: 1, value: 0},
Q2: {qid: 2, value: "Hello"},
},
];
var columns = [
{title: "PID", field: "pid"},
{title: "Title", field: "title"},
{title: "TA Test", field: "Q2.value",
formatter:"textarea",
editor: "textarea",
editorParams:{
elementAttributes:{
maxlength:"500",
}
},
}
];
var table = new Tabulator("#example-table", {
index:"pid",
height: "100%",
layout: "fitData",
columns,
data: data,
});
It looks to be a bug using the textarea with the table height option set to a percentage. If you use a pixel value, then it works as expected.
I would recommend you fill out a bug report against the github project. https://github.com/olifolkerd/tabulator/issues/new?assignees=&labels=Possible+Bug&template=bug_report.md&title=
The bug report template shows you what information is needed for the bug to be easy to replicate and fix.
(If you don't have a Github account, then I can create the bug report.)

Is this consistent behavior between "select" and "autocomplete" options of Tabulator?

to replace raw values I use "lookup" feature of Tabulator.
But "select" and "autocomplete" behaves differently
var country_list = {
1: "Germany",
2: "Ukraine",
3: "Canada",
};
//Build Tabulator
var table = new Tabulator("#example-table", {
height:"311px",
data: tabledata,
columns:[
{title:"ID", field:"id", width:40 },
{title:"Country", field:"country_id", width:130,
editor:"select",
editorParams:{values: country_list, },
formatter : "lookup",
formatterParams : country_list,
},
{title:"Country2", field:"country_id", width:130,
editor:"autocomplete",
editorParams:{values: country_list, },
formatter : "lookup",
formatterParams : country_list,
},
],
});
Try to edit Country and Country2 fields:
JSFiddle
"select" displays label, but "autocomplete" displays raw value.
Is this behavior consistent?
If yes, how to force Tabulator to hide raw value?
This is a bug, a fi has been pushed to the 4.2 branch which should be released shortly

Amcharts: Column chart color

I followed this code http://jsfiddle.net/amcharts/w8Bcy/ to create my own column chart. I succed but now i want to improve that charts with other options.
Actual chart def is :
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"dataProvider": chartData,
"valueAxes": [{
"gridColor": "#FFFFFF",
"gridAlpha": 0.2,
"dashLength": 0
}],
"gridAboveGraphs": true,
"startDuration": 1,
"graphs": [{
"balloonText": "[[category]]: <b>[[value]]</b>",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"type": "column",
"valueField": "visits"
}],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "country",
"categoryAxis": {
"gridPosition": "start",
"gridAlpha": 0
},
"exportConfig": {
"menuTop": 0,
"menuItems": [{
"icon": '/lib/3/images/export.png',
"format": 'png'
}]
}
});
I have multiple column with some values, and i want the column to have a color based on their values. How i can change column color with value?
Example: Under x, column will be red .
Above x, column will be green .
I also want to trace a line with the reference value.
Thanks.
graph.colorField = "color"
and in data add field
"color" : "your color hex code "
its done check at http://jsfiddle.net/w8Bcy/68/ i have color all of them red , you can add color of your choice when your generating your data / json

Resources