I'm trying to create the ability to add custom columns to a tabulator table.
I have a db table where I have a title and field. I extract that info into a json and want that to be added to my table.
fetch("../includes/getCustomColumns.php")
.then(function(response) {
return response.json()
}).then(function(returned) {
window.customColumns = returned
console.log(window.customColumns)
})
Then in my table I have
{
title : "Custom Columns",
columns: [
window.customColumns,
],
}
But I get
Uncaught (in promise) TypeError: Cannot read property 'field' of undefined and tabulator.min.js:2 Invalid column definition option in 'undefined' column: ..
I can see the two columns in the console log and if I copy that into the table it works. I'm wondering if it ss it even possible to add customisable columns to Tabulator or am I simply on the wrong track.
without seeing the code more specifically than what you have here, I'm going to guess that because the fetch() is asynchronous, that window.customColumns is still undefined when you are creating the Tabulator. And then "sometime later" your fetch() sets the value, but it's too late.
You could use addColumn() to programatically add the response to your fetch() when it is received.
Related
I have a button on the Purchase Order record that performs a saved search query on the current record and then uses the http module to send that data via a POST to a url. That url then sends the data posted back as part of the success confirmation. The idea with the saved search is to create a javascript object that contains all the data that I want from the purchase order (main record and items sublist with subrecords) and then to use JSON.stringify to create a JSON payload for the http POST. I can't do this with the currentRecord because if you inspect it it only contains the internal id. This would also prevent me from having to go to the great lengths of writing a lot of code to manually build up a JSON string from the currentRecord.
Unfortunately I don't really understand how to specify the column names in the dynamically created saved search. Sometimes it looks to me like the column names are those from the NetSuite Records Browser and other times the script gives an error (column not found) if I use a column name from the NetSuite Records Browser (for example currencysymbol).
I'm also not sure how to specify columns that appear in sublists or subrecords in sublists. I tried to use item.itemtype but this gave me a column not found error. Just item completes successfully but I'm not sure whether this was really successfull since it is difficult to decode the returned result after the JSON.stringify (it adds a lot of backslashes). Using console.log (for some reason I don't get anything back using the NetSuite log.audit) is also quite difficult, although it looks like it is returning an array with 5 rows. So using item might sort of be successful. I say sort of because I have 3 item lines and it is returning 5 array rows.
So basically I would like to know where one can find the names of the columns to use in NetSuite for a saved search; and also how to specify sublist column names and sublist subrecord column names in a saved search.
/**
* #NApiVersion 2.0
* #NScriptType ClientScript
* #NModuleScope SameAccount
*/
define(['N/ui/dialog', 'N/currentRecord', 'N/record', 'N/url', 'N/http', 'N/search'], function (dialog, rec, record, url, http, s) {
function pageInit(context) {
// All client scripts need at least one dummy function.
} // pageInit
function onButtonClick() {
var currentRecord = rec.get();
// Create a saved search dynamically.
var rs = s.create({
type: s.Type.PURCHASE_ORDER,
filters: [
["mainline", s.Operator.IS, "F"], "and",
["internalid", s.Operator.IS, currentRecord.id]
],
columns: [
"internalid",
"currency",
{
name: "item",
sort: s.Sort.ASC // DESC
}
]
});
var myPostDataObj = rs.run().getRange(0, 1000);
console.log(myPostDataObj);
var headers = {
'Content-Type': 'application/json; charset=utf-8',
};
http.post.promise({
url: 'http://httpbin.org:80/post',
body: JSON.stringify(myPostDataObj),
headers: headers
})
.then(function(response){
console.log('SUCCESS: ' + JSON.stringify(response));
})
.catch(function onRejected(reason) {
console.log('ERROR: ' + JSON.stringify(reason));
})
}
return {
pageInit: pageInit,
onButtonClick: onButtonClick
};
}); // Define
There are two Chrome extensions I suggest you get;
NetSuite Field Explorer. This extension will show you the ids (and values) of all the fields in a NetSuite record.
NetSuite Search Export. This extension will convert/export a saved search to SuiteScript.
For what you're doing, I would create your saved search in the UI, and then export it using the Saved Search Export extension, paste that into your code (where s.create is), and work from there.
The first extension is nice to get to the sublist field ids. Saves a lookup in the record browser.
I'm trying to get all the data out of mongo database, but i want to filter one specifically.
What i'm trying to do is. Get someone to click on my portfolio to show them details about what i created. But on left sidebar i want to show other work that i've done. Check pictures and you should understand better.
router.get('/portfolio/:id', function(req, res, next) {
Work.findById(req.params.id, function(err, foundWork) {
console.log(foundWork)
if (err) {
console.log(err);
} else {
res.render('portfolio', {
title: 'Portfólio',
work: foundWork
});
}
});
});
Picture
FindById only showing the result of one specific project.
Thanks for your help
EDITED-----------------------------------------------------
So i changed the code to get all data from DB and filtered item that i need by id. I can't parse the data through to ejs. When i console.log data in nodejs i get data. When i console log in ejs i get undefined.
Here is the pic what i get in nodejs.
Console.log
I noticed when i loop through the filtered item i get all data i need. I dont think it's right to loop through data when i'm onlz parsing one item to ejs.
So i figured this out myself.
I did as the user givehug said. It worked but then i had to loop through the filtered items again in ejs despite there is only one item. EJS doesnt know how many items as left in filtered array so i looped through. Got one item out and then i rendered it and it worked.
you have to add a new property to your schema to classify your work. for example,
in your schema:
{workType:{type:String}} //either required or no
when you post your data, add this property too
{workType:"other"} //i just made it up
query like this:
const other=await Work.find({workType:"other"})
now you will get the data that u need.
I have a search page, where user enter fields and click on search button. Then I am making ajax call to Sharepoint 2013 list with search query and fetching data. After fetching data I am binding data to Kendo grid.
This SharePoint list contains different type of fields like: look up, choice, text field. Data from choice column, text field types are getting bind to grid easily, I am able to see the data too. But data from look up columns is not being seen in Kendo Grid.
Instead of data, its showing
[object Object]
Below is the code of ajax call I am making and in success I am binding data to Kendo Grid.
function fetchData(webUrl, filterString){
$.ajax({
url: webUrl +"/_api/web/lists/getByTitle('Inventory')/Items?$filter="+filterString,
method: 'get',
contentType: 'application/json;odata=verbose',
headers:{
'X-RequestDigest': $('#__REQUESTDIGEST').val(),
'Accept': 'application/json;odata=verbose'
},
success: function(data){
var grid = $('#grdInventory').getKendoGrid();
grid.dataSource.data(data.d.results);
grid.refresh();
}
});
}
Below is the screenshot of the Grid: In Grid=
ID, short description, Analytic ID, Analytic Name are text type column
Production status is choice column,
State, Platform are look up column in SharePoint
Below is the screenshot of data being seen in Browser Console:
Can anyone please help me or give me hint of how to display look up column data in Kendo Grid.
That's a standard behavior, Lookup field values in that case represent a complex property and returned as object. Depending on what field from lookup list should be displayed (lets assume Title in our example), you could apply the following filter for returned data before the grid is getting displayed:
var items = data.d.results.map(function(item){
item.State = item.State.Title; //lets get Title from Lookup object
return item;
});
and then bind the data:
var grid = $('#grdInventory').getKendoGrid();
grid.dataSource.data(items);
grid.refresh();
My GET JSON brings back from COUChDB
{"total_rows":6,"offset":0,"rows":[
{"id":"51585142d8f2851d34c9b7dc8c003997","key":"itemName","value":{"nestedkey1":"nestedvalue1","nestedkey2":"nestedvalue2","nestedkey3":"nestedvalue2","nestedkey4":"nestedvalue4","nestedkey5"}},
I want to remove {"total_rows":6,"offset":0,"rows":[
{"id":"51585142d8f2851d34c9b7dc8c003997","key":"itemName"
So I am left with the wrapper/parent "value" that has the nested keys and nested values I really want and so it is presented in the following JSON format {"nestedkey1":"nestedvalue1","nestedkey2":"nestedvalue2","nestedkey3":"nestedvalue2","nestedkey4":"nestedvalue4","nestedkey5"}}, as my json
I've tried CouchB mapping/views and jquery client side function/result filtering but I'm new to this and could use some insight into achieving my objective
You should be able to achieve this using jQuery on the client side. You could do this in the success callback of get()
var value = [];
$.get( "url/to/view", function( data ) {
$.each(data.rows, function(index, row){
value.push(row.value);
});
});
That way, you have the rows in data.
So I have a User model which is connected to projects via a junction table. This junction table has some additional attributes like allow_read which I want to pass back in my response.
request.user.getProjects({
where : { do_sync : true, allow_read : true },
}).success(function(projects) {
// send proper response
response.jsonp(projects);
}).error(function(err) {
// send error response
response.status(500).jsonp(err);
});
In this code block 'allow_read' works properly and projects[0].user_project returns the additional attributes from the User_Project model. The problem is when 'projects' get serialized the user_project object disappears. projects[0].values also does not contain a user_project property even though projects[0].user_project does exist.
My question is if there is anyway for sequelize to automatically stringify both the projects and their junction table attributes without manually building that object myself?