I'm trying the code:
{title:"Age", field:"age", align:"left",
formatter:function(cell, formatterParams){
var value = cell.getValue();
if(value > 20){
cell.getRow().getElement().css({
"background-color": "#ffbe33"
});
return value;
}else{
cell.getRow().getElement().css({
"background-color": "transparent"
});
return value;
}}
}
But get an error:
TypeError: cell.getRow(...).getElement(...).css is not a function
If you are using Tabulator 4.0 or greater it returns a DOM Node from the getElement function so you need to use the .styles property:
cell.getRow().getElement().style.backgroundColor = "#ffbe33";
Related
I create a table.
There is a column which has editor:"autocomplete", listItemFormatter, searchFunc, formatter:"lookup"
Here is its setting:
let column = {title: "Показателя", field:"parameter", editor:"autocomplete",
editorParams: {
values: values,
listItemFormatter: (value, title) => {
if (this.displayGroupTitle && value !== undefined) {
return title + " - (" + this.parameters.find(parameter => String(parameter.id) === value).groupTitle + ")"
} else {
return title
}
},
allowEmpty: true,
searchFunc: (term, values) => {
let matches = []
let foundParameters = findParameterByTerm(term, this.parameters)
values.forEach(function(item){
if(foundParameters.indexOf(item.value) !== -1){
matches.push(item);
}
});
return matches;
},
// showListOnEmpty: true
},
formatter:"lookup",
formatterParams: values
}
When I start to edit cells with value, cells show value instead of the title of value.
There's an inactive cell here:
But it's the same cell when I edit it:
How to do to show title when I edit cell with value?
UPDATE:
Values variable has:
{
"40":"Выручка",
"41":"Чистая прибыль",
"42":"Прибыль до налогооблажения",
"43":"Выловая прибыль",
"44":"Себестоимость продаж",
"45":"Финансовые доходы",
"46":"Финансовые расходы"
}
I have a drop down that, when a particular option is selected a hidden field will be displayed and that field which have a new value. I am able to get the field to display but am not able to populate the field with the value. Script below:
function fieldChanged(context) {
var records = context.currentRecord;
if (context.fieldId == 'custbody_data') {
var note = context.currentRecord.getField({ fieldId: 'custbody_note' });
var type = records.getValue({
fieldId: 'custbody_data'
});
if (type == "2") {
note.isDisplay = true;
note.setValue = "test";
} else if (type == "1") {
note.isDisplay = false;
note.setValue = "";
}
}
}
return {
fieldChanged: fieldChanged
}
note.setValue = "";
There are two problems in what you are trying to do:
With the NetSuite API, to manipulate the value of fields in the record you need to use the N/currentRecord#Record object , not the N/currentRecord#Field. In other words you need to be calling context.currentRecord.setValue().
setValue is a method, not a property. I.e. you need to call the function setValue() with the new value, and not assign it a value (note.setValue = "new value") like you are attempting.
Putting those together, the correct syntax for updating a field value is:
context.currentRecord.setValue({
fieldId: 'custbody_note',
value: "test",
});
I need to hide a field in a record if a certain option is selected in a drop down field. Using the below code no matter what choice I make in the drop down the field is hiding. Any help appreciated:
define([], function () {
/*Field Change event*/
function fieldChanged(context) {
var records = context.currentRecord;
if (context.fieldId == 'custbody_pick_ship') {
var customElement = context.currentRecord.getField({ fieldId: 'custbody_zone' });
var type = records.getValue({
fieldId: 'custbody_pick_ship'
});
if (type = "Pick Up") {
customElement.isDisplay = false;
} else {
customElement.isDisplay = true;
}
}
}
return {
fieldChanged: fieldChanged
}
}
);
Your problem lies in the line if (type = "Pick Up"). A single = in JavaScript is an assignment operator, which means you are setting the value of the type variable to "Pick Up". As "Pick Up" is a non-falsy value that expression will always evaluate as true. You need to use either == or === to test equality (in general the triple equal is preferable).
if (type === "Pick Up") {
customElement.isDisplay = false;
} else {
customElement.isDisplay = true;
}
I have a geojson file which I'm getting from this website which somehow contains corrupt data, with a coordinate value = null.
http://measuringamsterdam.nl/datalist/kijk/
And I'm using it in my code like this:
//Retrieve all data and add to map
$.each(datalistObject['idlist'], function(key, value) {
$.getJSON('http://measuringamsterdam.nl/datalist/kijk/' + value['id'], function(data) {
textbox = value['name'];
var dataid = L.geoJson([data], {
style: function (feature) {
return feature.properties && feature.properties.style;
},
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: value['icon']
});
}
}).addTo(jsonGroup);
console.log(jsonGroup);
},function(xhr) { console.error(xhr); });
});
Now somehow I need to filter out the features/objects where the coordinates have a null value.
I really need to filter the data that point in my code since I need the + value['id'] part in the getJSON code.
Ane ideas?
Using the following code you will generate a new array. Which will include only the filtered data.
var newArray = data.filter(function (el) {
return el.value != 'null';
});
You can also apply multiple filters, for example:
return el.value_a != 'null' && el.value_b > 100;
Hopefully this will work!
I have a custom multi-select drop-down element in one of my kendo grid header columns titled "Status". Each selection in the drop-down represents many statuses, but they are grouped together for simplicity, and so we can show groups of like statuses.
Since this is a custom filter, I know I have to manipulate the kendo filter manually, and this seems to be giving me fits.
When any selection is changed in my custom drop-down, I fire off a function to modify the filters (the section where I spin through the status array has been truncated for easier reading):
// Apply the status filters from the multi-select drop down
function applyStatusFilter(statusValues) {
var gridData = $("#accountsGrid").data("kendoGrid");
var currentFilterObj = gridData.dataSource.filter();
var currentFilters = currentFilterObj ? currentFilterObj.filters : []; // If there are no current filters, set to empty array
var statusFilters = { logic: "or", filters: [] };
var statusArray = statusValues.split(','); // Convert status selections to array
// Remove any pre-existing status filters from the existing filter
if (currentFilters && currentFilters.length > 0) {
for (var i = 0; i < currentFilters.length; i++) {
if (currentFilters[i].field == 'status') {
currentFilters.splice(i, 1);
//break;
}
}
}
if (statusArray[0].length > 0) {
$.each(statusArray, function (key, value) {
if (value == 'AC') {
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "A"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "G"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "O"
});
if (value == 'OH') {
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "G"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "H"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "I"
});
}
});
}
currentFilters.push(statusFilters);
gridData.dataSource.filter({
logic: "and",
filters: currentFilters
});
}
This isn't working as expected, although it's still a work in progress. There are two main issues; when I call this function, I want to remove all current "status" related filters, then rebuild. I can't clear all filters, as I need to maintain other column filters that might be applied. My remove status filters block doesn't seem to be working.
Second big issue, is how to properly combine two filter objects; when one can be a nested blocked of status filters using "or" logic, then combining it to any possible existing filters using "and" logic between the two filter objects.
About your first issue. There are sure several ways to remove all current "status" related filters, but I have built a recursive function that clear the filters for a given column.
function clearFilter(filter, columnToClear) {
if (filter == undefined)
return filter;
if (filter.logic != undefined) {
filter.filters = $.map(filter.filters, function (val) {
if (val.field == undefined && typeof (val.filters) == "object" && typeof (val.logic) == "string") {
val.filters = clearFilter(val.filters, columnToClear)
if (val.filters.length == 0)
val = null;
return val;
}
else if (val.field != columnToClear)
return val;
});
if (filter.filters.length == 0)
filter = null;
}
else {
filter = $.map(filter, function (val) {
if (val.field != columnToClear)
return val;
});
}
return filter;
}
In your case the function should be called as:
clearFilter(currentFilterObj, "status");