I have added few columns in table using hook. Now some column are coming directly from collection and some are getting computed using hook. I want to show them in specific order in my table. How do I do that? Currently I am able to either add computed columns at beginning or end by using concat function
Please add details and examples.
Sure ...I have created hook ..below is the code from Data.js
export function Angelbayinvestor_afterQuery(item, context) {
let Return = '';
item.Investmentamount = item.noOfShares * item.purchasePrice;
item.Currentvaluation = item.noOfShares * item.currentSharePrice;
Return = (item.Currentvaluation / item.Investmentamount).toFixed(2).toString();
item.Return = Return + 'x';
item.Qty = item.noOfShares.toLocaleString()
return item;
}
/* code on page */
$w.onReady(function () {
$w("#radioGroup1").value = 'CUR' // "first_value"
$w('#table1').show();
$w('#table2').hide();
$w("#html1").hide();
$w("#html2").hide();
currentUser.getEmail()
.then( (email) => {
userEmail = email;
console.log(userEmail);
$w("#dataset1").onReady(() => {
$w("#dataset1").setFilter(wixData.filter()
.eq("email", userEmail)
).catch((err) => {
console.log('in error' + err);
})
const currentColumns = $w("#table1").columns;
const calculatedColumns = [
{
"id": "colinvestmentamount",
"dataPath": "Investmentamount",
"label": "Investment Amount",
"type": "string",
},
{
"id": "colcurrentvaluation",
"dataPath": "Currentvaluation",
"label": "Current Valuation",
"type": "string",
},
{
"id": "colreturn",
"dataPath": "Return",
"label": "Return",
"type": "string",
},
{
"id": "colqty",
"dataPath": "Qty",
"label": "Quantity",
"type": "string",
}
];
$w("#table1").columns = (currentColumns).concat(calculatedColumns);
})
I think that after you set the columns you should bund the data to the table, using $(“#table1”).rows =
https://www.wix.com/velo/reference/$w/table/rows