I want to print a boolean value from JSON into a table, if I access directly to the status field, an empty value is displayed
here is an example of json file:
{
'name':'client'
'status':true,
'method':'masterCard',
'amount':'1700',
}
jsx file :
const columns = [
{
title: "name",
dataIndex: "name",
key: "name",
width: "20%"
},
{
title: "status",
dataIndex: "status",
key: "status",
width: "20%"
},
{title: "Method Paiment",
dataIndex: "method",
key: "method",
width: "20%",
}]
The solution i found is to do a condition (is true or false ):
const columns = [
{
title: "name",
dataIndex: "name",
key: "name",
width: "20%"
},
{
title: "status",
dataIndex: "status",
key: "status",
width: "20%",
render: statut => {
if (statut == true) {
return (
<Tag color="#1890ff" key={statut}>
Is True
</Tag>
);
}
return (
<Tag color="#d48806" key={statut}>
Is False
</Tag>
);
}
},
{title: "Method Paiment",
dataIndex: "method",
key: "method",
width: "20%",
}]
Related
I have added clickEvent in my code fo MDBDataTable. I have some columns in table, I have added clickEvent but it applying for all columns. I need click event for all columns except "addBtn" column. Becausse it is contains buttons - Edit and Delete.
const data = {
columns: [
{
label: "First Name",
field: "firstName",
sort: "asc",
width: 150,
},
{
label: "Last Name",
field: "lastName",
sort: "asc",
width: 150,
},
{
label: "Email",
field: "email",
sort: "asc",
width: 270,
},
{
label: "Role",
field: "authorities",
sort: "asc",
width: 200,
},
{
label: "Contact",
field: "phoneNumber",
sort: "asc",
width: 100,
},
{
label: "Type",
field: "userType",
sort: "asc",
width: 100,
},
{
label: "Action",
field: "addBtn",
sort: "asc",
width: 300,
},
],
rows:
userdData &&
userdData.length > 0 &&
userdData.map(rec => {
return {
firstName: rec?.firstName,
lastName: rec?.lastName,
email: rec?.email,
authorities: rec?.authorities[0],
phoneNumber: rec.phoneNumber !== null ? rec.phoneNumber !== null : "",
userType: rec?.userType,
addBtn: actionButtons(rec, rec?.id),
clickEvent: () => handleClick(rec)
}
}),
}
I have attached screen shot of the my page
I have columns like this :-
const columns = [
{
field: "truck_in_time",
title: "Truck in time",
editable: "never",
},
{
field: "truck_out_time",
title: "Truck out time",
editable: "never",
},
{
field: "document",
title: "Document",
width: 160,
render: (params) => {
return (
<>
<button
onClick={() => console.log(params)}
className="productListEdit"
>
Upload
</button>
</>
);
},
editable: "never",
},
{
field: "remarks",
title: "Remarks",
width: 160,
editable: "onUpdate",
},
];
I want something for upload like we have for the edit button.When we select a file through upload button, we get that data and can send it to our backend api.
The following Kendo grid with a dropdown. The dropdown AccountCode item is in form of an object as below;
The following is used to display the details;
function loadGrid() {
$("#grdItems").kendoGrid({
dataSource: itemDS,
pageable: {
refresh: false,
pageSizes: false
},
aggregate: [{ field: "Amount", aggregate: "sum" }],
columns: [ {
field: "CostCenter",
title: "Cost Center",
editor: costCenterDropDownEditor,
template: "#:CostCenter.Description#"
}, {
field: "AccountCode",
title: "Account Code",
editor: accountDropDownEditor,
template: "#AccountCode.AccountDescription#"
}, {
field: "Description",
}, {
field: "BillNumber",
title: "Bill Number",
},
{
field: "Amount",
format: "{0:n}",
footerTemplate: "Sum: #= kendo.toString(sum, 'n')#"
},
{ command: [{ name: "edit", text: "MODIFY" }], title: " ", width: "120px" }],
editable: "popup"
});
}
and it looks like this when displayed;
How can I insert a placeholder when the dropdown object is empty as shown in the first image? Tried the usual placeholder tag, but it doesn't seem to work.
EDIT: Code added
I'm pretty sure those strings are just javascript code.
"#:CostCenter.Description.length > 0 ? CostCenter.Description : 'placeholder'#"
I am using jqxTreeGrid widget and running into a TypeError: Cannot set property 'treeGrid' of null error.
I've come across some sources that said that the div which the table is being attached to is not being found but I console.log the div and it was found.
Any other suggestions what might be causing this issue?
VIEW
<div id="treeGrid"></div>
SCRIPT
var tableDiv = $("#treeGrid");
var tableData = <%=raw #array_with_data.to_json%>;
var treeSource, treeData;
treeSource = {
dataType: "json",
dataFields: [
{ name: "id", type: "number" },
{ name: "foo_id", type: "number" },
{ name: "foo_name", type: "string" },
{ name: "bar_id", type: "number" },
{ name: "bar_name", type: "string" },
{ name: "noob_name", type: "string" }
],
hierarchy: {
keyDataField: { name: "id" },
parentDataField: { name: "foo_id" }
},
id: "id",
localData: tableData
};
treeData = new $.jqx.dataAdapter(treeSource);
treeData.dataBind();
// build table as a tree table:
tableDiv.jqxTreeGrid({
width: "100%",
source: treeData,
sortable: true,
filterable: true,
pageable: true,
selectionMode: "singleRow",
columns: [
{ text: "ID", dataField: "id", hidden: true },
{ text: "Foo ID", dataField: "foo_id", columnGroup: "foo", width: "20%" },
{ text: "Foo Name", dataField: "foo_name", columnGroup: "foo", width: "20%" },
{ text: "Bar ID", dataField: "bar_id", columnGroup: "bar", width: "20%" },
{ text: "Bar Name", dataField: "bar_name", columnGroup: "bar", width: "20%" },
{ text: "Noob Name", dataField: "noob_name", columnGroup: "noob", width: "20%" }
],
columnGroups: [
{ text: "Foo", name: "foo" },
{ text: "Bar", name: "bar" },
{ text: "Noob", name: "noob" }
]
});
I had the same problem.
My problem was, that I included jqxdatatable.js AFTER jqxtreegrid.js
WRONG:
<script type="text/javascript" src="/js/jqwidgets/jqxtreegrid.js"></script>
<script type="text/javascript" src="/js/jqwidgets/jqxdatatable.js"></script>
CORRECT:
<script type="text/javascript" src="/js/jqwidgets/jqxdatatable.js"></script>
<script type="text/javascript" src="/js/jqwidgets/jqxtreegrid.js"></script>
When I put it before the other include, it worked
in Kendo UI Grid (with Angularjs) i have the following grid:
<div kendo-grid k-data-source="Table" k-options="thingsOptions" style="height: 365px">
$scope.thingsOptions = {
sortable: "true",
scrollable: "true",
toolbar: [{ name: "create", text: "Aggiungi Prodotto" }],
columns: [
{ field: "Name", title: "Name", width: "50px" },
{ field: "Description", title: "Description", width: "50px" },
{ field: "Price", title: "Price", width: "50px" },
{ field: "Active", title: "Active", template: '<input type="checkbox" disabled="disabled" #= Active ? checked="checked":"" # class="chkbx" />', width: "20px" },
{ command: [{ name: "edit", text: "Modifica" }], title: "", width: "172px" }
],
editable: "inline"
};
How can i make the "Price" field readonly on some condition? I must test a variable and if it is true i want the Price field readonly otherwise writable.
I have tried to add in the "thingsOptions" function:
edit: function (e) {
if(myvar == true)
e.container.find("input[name=Price]").enable(false);
}
But id doesn't work (undefined reference).
Try to use:
edit: function (e) {
if(myvar == true)
$("input[name=Price]").attr("readonly", true);
} else {
$("input[name=Price]").attr("readonly", false);
}
}
Inside the edit function of the grid just manipulate the condition the way you want to use. For closing the cell you can use this.closeCell();
edit: function (e) {
//Size will be editable only when the Area is not empty
if(e.container.find(“input”).attr(“name”) == ‘Price’) {
//Below statement will close the cell and stops the editing.
if(myvar == true){
this.closeCell();
}
}
}
For more info have a look here
columns: [{
editable: false,
field: "Id",
title: "Id",
width: 50,
editor: idEditor,
}, {
title: "Name",
field: "Name",
width: 100
}, {
command: ["edit", "destroy"],
title: " ",
width: "250px"
}]
function idEditor(container, options) {
container.append(options.model.Id);
}