dgrid/Grid setting dynamic column field - dgrid

I'm new to dgrid/Grid. I have problem when set the last field to columns of Grid. My data array:
[{
"StatisticType": "Năng suất lập trình",
"Language": "PHP",
"Phase": "Code - Review Code",
"ProjectType": "Customize/Full",
"Donvi": "KLOC/ManMonth",
"**HSL**": "2.2"
}, {
"StatisticType": "Năng suất lập trình",
"Language": "PHP",
"Phase": "Code - Review Code - UT",
"ProjectType": "Customize/Full",
"Donvi": "KLOC/ManMonth",
"**TTP**": "1.21"
}, {
"StatisticType": "Tỷ lệ bug phát hiện khi review source code",
"Language": "Tính chung các ngôn ngữ",
"Phase": "",
"ProjectType": "Customize/Full",
"Donvi": "bug/KLOC",
"**CCC**": "0"
}]
I save my data array to ViewBag.Data and here is my code:
<script>
var report = #Html.Raw(ViewBag.Data);
require([
'dojo/_base/declare',
'dstore/Memory',
'dgrid/OnDemandGrid'
], function (declare, Memory, OnDemandGrid) {
var store = new (declare([Memory]))({
data: report_#(i)
});
// Instantiate grid
var grid = new (declare([OnDemandGrid]))({
collection: store,
columns: {
StatisticType: 'Số liệu thống kê',
Language: 'Ngôn ngữ LT',
Phase: 'Công đoạn',
ProjectType: 'Loại Project',
Donvi: 'Đơn vị tính',
"The last field of column"
(if I set HSL: 'HSL' it's okay but the other fields??)
}
}, 'grid');
grid.startup();
});
</script>
I had read https://github.com/SitePen/dgrid/blob/v0.4.3/doc/components/core-components/Grid.md but have no idea. Can any one help me?
Thanks a lot!

Finally, I solved my problem.
First, get your data as a datatable, then you convert it into a json array.
Second, in html you bind Json array to the Grid's store.
Because the last column is dynamic, so you can get datatable column and convert to Json array to use in HTML.
Hope this help someone else.

Related

Select data binding in SAPU15

I read the documentation https://sapui5.hana.ondemand.com/#/api/sap.m.Select and tried to do a small example. I created my value in my function onInit of my controller:
var oData = {
"SelectedProduct": "test1",
"ProductCollection": [
{
"ProductId": "test1",
"Name": "test 1"
},
{
"ProductId": "test2",
"Name": "test 2"
},
{
"ProductId": "test3",
"Name": "test 3"
}
]
};
var oModel = new JSONModel(oData);
this.getView().setModel(oModel, "myTest");
I want that my selectedProduct default value is test1 so I init it to test1.
In my xml file, i created my selector as following:
<Select
id="idSelect"
forceSelection="false"
selectedKey="{myTest>/SelectedProduct}"
change="_change"
items="{
path: 'myTest>/ProductCollection'
}">
<core:Item key="{myTest>/SelectedProduct}" text="{myTest>Name}" />
</Select>
So, everytime i change the value, my following code is made:
_change: function () {
console.log("_changeAblauf");
console.log(this.getView().byId("idAblaufbriefeSelect").getSelectedItem());
console.log(this.getView().byId("idAblaufbriefeSelect").getName());
},
My issue is that the print always display the content of my SelectedProduct from oData and not from the selector..
Why it don't take the value from the selector and how can i read my new value of the selector ?
In the key property of the Item you should bind myTest>ProductId: this value will populate your model SelectedProduct property every time the change event will be fired.

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

Retrieve related invoice of an applied payment in NetSuite SuiteScript 2.0

I have a requirement; where I need to load a list of payments that were updated between a specified date/time range. And for each invoice; I need to get a list of internal id (aka invoice id) that payment has been applied to (since a payment can be applied to one or more invoices).
I tried to achieve this using a search query like this:
var paymentSearch = search.create({
type: search.Type.CUSTOMER_PAYMENT,
filters: [
['lastmodifieddate', 'within', from_datetime, to_datetime],
'and',
['appliedToTransaction.tranid', search.Operator.ISNOTEMPTY, '#NONE']
],
columns: [
'entity',
'tranid',
search.createColumn({
name: 'internalid',
join: 'appliedToTransaction'
})
]
});
for (var i = 0; i < paymentsPagedData.pageRanges.length; i++) {
var currentPage = paymentsPagedData.fetch(i);
currentPage.data.forEach(function(result) {
// TEST
var appliedToInvoiceIds = result.getValue({ name: 'internalid', join: 'appliedToTransaction' });
}
}
When I inspected the appliedToInvoiceIds, it only appears to be returning a single value, the first invoice this payment has been applied to. How can I get all of the invoice ids that the payment has been applied to?
I tried inspecting the result object (inside the forEach loop) to see what was inside and this is what I saw:
{
"recordType": "customerpayment",
"id": "25911",
"values": {
"entity": [
{
"value": "761",
"text": "COMPANY NAME INC"
}
],
"tranid": "722",
"appliedToTransaction.internalid": [
{
"value": "2676",
"text": "2676"
},
{
"value": "2658",
"text": "2658"
}
]
}
}
As you can see on the result object of the payment; it has appliedToTransaction.internalid which is an array and has two items in it. How can I retrieve these?
Is there an alternate version of result.getValue(...) available for retrieving array of items/field values via a join?
You need to return true at the end of your forEach. Otherwise it will only return one result.

BookshelfJS: all ints are being returned as strings [pg]

bool seems to work as expected, as does json type (postgres), but all of my id cols populate as strings (breaking the front-end code)
Is there a way to a. fix it, or b. tell bookshelf that that field is an integer?
Update
By request, here's some code snippets. I'm just testing the waters with node/bookshelf, so this isn't complicated code; it's mostly right out of the getting started guide. The database is an existing one we've been using for 2ish years, the id cols are definitely int for all tables
One good example, Calendars and
var Appointment = bs.Model.extend({
tableName: 'ec__appointments',
});
var Calendar = bs.Model.extend({
tableName: 'ec__calendars',
appointments: function() {
return this.hasMany(Appointment, 'calendar_id');
},
});
For this one, the calendar ids come down as int, but when I fetch({withRelated:['appointments']}), the appointment.id is a string.
{
"calendars": [
{
"id": 2,
"name": "Default Calendar",
"created_at": "2015-03-06T09:35:58.000Z",
"updated_at": "2016-03-23T03:28:07.000Z",
"appointments": [
{
"id": "107",
"calendar_id": "2",
"name": "Test",
"starts_at": null,
"ends_at": null,
"created_at": "2015-05-29T23:13:20.000Z",
"updated_at": "2015-05-29T23:13:20.000Z",
},
You can fix this problem with the following code:
var pg = require('pg');
pg.types.setTypeParser(20, 'text', parseInt);
More details here: https://github.com/tgriesser/knex/issues/387

Resources