Hide empty group in Ag-grid after row update - grouping

How to remove empty groups from ag-grid after updateRowData. In the plnkr example, I am modifying country value for the row, I expect group name to be changed but instead a new group is created.
Code for modifying country name:
let toBeUpdate = [];
this.gridApi.forEachNode((rowNode, index) => {
if(rowNode.data && rowNode.data.athlete == 'Sadiq Khoja'){
var data = rowNode.data;
data.country = 'AAA Unknown X';
toBeUpdate.push(data);
}
});
this.gridApi.updateRowData({update:toBeUpdate});
https://plnkr.co/edit/PTuwR5zejS2xiLIg
(Press 'Add' button to change the country name)

UpdateRowData works when there is no row group.
In this case, instead of using updateRowData try using setRowData -
this.gridApi.setRowData(toBeUpdate);
This will also refresh the grid to reflect the changes in the row.
For more information you can read here - https://www.ag-grid.com/documentation/javascript/data-update/

The correct way to update your data would be to use the setDataValue on rowNode (see here).
Once you update your data, you need to refresh your view for grouping via the api by calling refreshClientSideRowModel.
So your update funciton should be as follows:
this.gridApi.forEachNode((rowNode, index) => {
if(rowNode.data && rowNode.data.athlete == 'Sadiq Khoja'){
rowNode.setDataValue('country', 'AAA Unknown X');
}
});
this.gridApi.refreshClientSideRowModel('group');
Demo

Related

Netsuite Suitescript - Chain of If statements always returns same result

I have a suitelet which I have managed to get working. however there is an issue.
I have a button on a saved search which is loading parameters.
I need to check a different box on an item record dependent on the values passed.
However it seems that only the top If statement is operated on regardless of the name of the field_id that get's passed.
What am I missing about the way these statements work?
The button link is here:
'<button onclick="window.open(/app/site/hosting/scriptlet.nl?script=602&deploy=1&compid=********&field_id=' || {systemnotes.field} || ' &rec_id=' || {internalid} || ');>Approve'
So it the system notes field I am trying to split the checkbox action on.
The actual script is here:
/**
* #NApiVersion 2.x
* #NScriptType Suitelet
* #NModuleScope SameAccount
*/
define (['N/record'], function (record) {
function onRequest(scriptContext) {
var rec_id=scriptContext.request.parameters.rec_id; //getting parameter
var field_id=scriptContext.request.parameters.field_id; //getting parameter
var itemRecObj= record.load({ type: record.Type.INVENTORY_ITEM, id: rec_id, isDynamic:true });
if(field_id='custom field 1'){
itemRecObj.setValue({ fieldId: 'checkbox1', value: true });
itemRecObj.save();
}
else if(field_id='custom field 2'){
itemRecObj.setValue({ fieldId: 'checkbox2', value: true });
itemRecObj.save();
}
}
return {
onRequest: onRequest
};
});
Only the custom field 1 statement is acted on, if I swap them and put the custom field 2 details above then only checkbox 2 is checked.
I need to create a substantial list of these statements and only check the box where the field_id matches.
Thanks in advance.

APEX row selector part 2

This is a follow on to "APEX row selector" posted 5 days ago.
The problem was collecting multiple values from an interactive grid. From the excellent links to post supplied I was able to achieve this. However, the next part of the project is to open an edit dialog page and update multiple values.
I added this code to the attribute of the interactive grid:
function (config)
{
var $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions3");
toolbarGroup.controls.push(
{
type: "BUTTON",
action: "updateCar",
label: "Edit Selected Cars",
hot: true,
});
config.toolbarData = toolbarData;
config.initActions = function (actions)
{
// Defining the action for activate button
actions.add(
{
name: "updateCar",
label: "Edit Selected Cars",
action: updateCar
});
}
function updateCar(event, focusElement)
{
var i, records, model, record,
view = apex.region("ig_car").widget().interactiveGrid("getCurrentView");
var vid = "";
model = view.model;
records = view.getSelectedRecords();
if (records.length > 0)
{
for (i = 0; i < records.length; i++)
{
record = records[i];
alert("Under Development " + record[1]);
vid = vid + record[1] + "||";
apex.item("P18_CAR").setValue(vid);
// need to open next page here and pass parameters
}
}
}
return config;
}
I need to know how to open a form and have the parameter values available to pass to an oracle update script.
Thank you for any help you can provide. I did find some posts but I really need a good example. I have tried everything to no avail.
There are various ways you could do this. Here's one way, perhaps someone else will offer a more efficient option.
The JavaScript options for navigation in APEX are documented here:
https://docs.oracle.com/en/database/oracle/application-express/19.1/aexjs/apex.navigation.html
Since you're trying to open a separate page, you probably want to use apex.navigation.dialog, which is what APEX automatically uses when opening modal pages from reports, buttons, etc.
However, as noted in the doc, the URL for the navigation must be generated server-side for security purposes. You need a dynamic URL (one not known when the page renders), so you'll need a workaround to generate it. Once you have the URL, navigating to it is easy. So how do you get the URL? Ajax.
Create an Ajax process to generate the URL
Under the processing tab of the report/grid page, right-click Ajax Callback and select Create Process.
Set Name to GET_FORM_URL.
Set PL/SQL code to the following
code:
declare
l_url varchar2(512);
begin
l_url := apex_page.get_url(
p_application => :APP_ID,
p_page => 3,
p_items => 'P3_ITEM_NAME',
p_values => apex_application.g_x01
);
apex_json.open_object();
apex_json.write('url', l_url);
apex_json.close_object();
end;
Note that I'm using apex_item.get_url to get the URL, this is an alternative to apex_util.prepare_url. I'm also using apex_json to emit JSON for the response to the client.
Also, the reference to apex_application.g_x01 is important, as this will contain the selected values from the calling page. You'll see how this was set in the next step.
Open the URL with JavaScript
Enter the following code in the Function and Global Variable Declaration attribute of the calling page:
function openFormPage(ids) {
apex.server.process(
'GET_FORM_URL',
{
x01: ids.join(':')
},
{
success: function (data) {
var funcBody = data.url.replace(/^"javascript:/, '').replace(/\"$/,'');
new Function(funcBody).call(window);
},
error: function (jqXHR, textStatus, errorThrown) {
console.error(errorThrown);
// handle error
}
}
);
}
In this case, I'm using apex.server.process to call the server-side PL/SQL process. Note that I'm passing the value of ids.join(':') to x01. That value will become accessible in the PL/SQL code as apex_application.g_x01. You can use additional items, or you can pass a colon-delimited string of values to just one item (as I'm doing).
The URL that's returned to the client will not be a standard URL, it will be a JavaScript snippet that includes the URL. You'll need to remove the leading and trailing parts and use what's left to generate a dynamic function in JavaScript.
This is generally frowned upon, but I believe it's safe enough in this context since I know I can trust that the response from the process call is not malicious JavaScript code.
Add a security check!!!
Because you're creating a dynamic way to generate URLs to open page 3 (or whatever page you're targeting), you need to ensure that the modal page is protected. On that page, create a Before Header process that validates the value of P3_ITEM_NAME. If the user isn't supposed to be able to access those values, then throw an exception.

Google Tag Manager: update cookie value and fire tag if value has changed

I have the follow JS variable:
function() {
var products = [];
prods.forEach(function(prod) {
products.push(prod.ACode + '-' + prod.BCode);
});
return products.join('|');
}
The output is an array that contains codes like these:
C1K-DR|A2D-AH|B1T-S1|
These values are being pushed into a cookie. I'm simply struggling because when the value of the push changes, the cookie doesn't get updated.
After that, I would like to fire a tag based only IF this value has changed.
Thanks anyone who can help.

Parsing email with Google Apps Script, regex issue?

I used to be quite proficient in VBA with excel, but I'm currently trying to do something with Google Scripts and I am well and truly stuck.
Basically, I am trying like to extract data out of a standardised email from Gmail into a Google sheet. There are a couple of other threads on the subject which I have consulted so far, and I can get the body of the email into the sheet but cannot parse it.
I am new to regex, but it tests OK on regex101
I am also brand new to Google Script, and even the debugger seems to have stopped working now (it did before, so would be grateful if anyone can suggest why this is).
Here is my basic function:
function processInboxToSheet() {
var label = GmailApp.getUserLabelByName("NEWNOPS");
var threads = label.getThreads();
// Set destination sheet
var sheet = SpreadsheetApp.getActiveSheet();
// Get all emails labelled NEWNOPS
for (var i = 0; i < threads.length; i++) {
var tmp,
message = threads[i].getMessages()[1], // second message in thread
content = message.getPlainBody(); // remove html markup
if (content) {
// search email for 'of:' and capure next line of text as address
// tests OK at regex101.com
property = content.match(/of:[\n]([^\r\n]*)[\r\n]/);
// if no match, display error
var property = (tmp && tmp[1]) ? tmp[1].trim() : 'No property';
sheet.appendRow([property]);
} // End if
// remove label to avoid duplication
threads[i].removeLabel(label)
} // End for loop
}
I can append 'content' to the sheet Ok, but cannot extract the address text required by the regex. Content displays as follows:
NOPS for the purchase of:
123 Any Street, Anytown, AN1 1AN
DATE: 05/05/2017
PRICE: £241,000
Seller’s Details
NAME: Mrs Seller
Thanks for reading :)
The return value of .match() is an array. The first captured group, containing the address, will be at index 1.
Based on the following line after your call to .match(), it looks like the tmp variable should have been assigned that array, not the property variable.
var property = (tmp && tmp[1]) ? tmp[1].trim() : 'No property';
That line says, if .match() returned something that isn't null and has a value at index 1, then trim that value and assign to property, otherwise assign it the string 'No property'.
So, try changing this line:
property = content.match(/of:[\n]([^\r\n]*)[\r\n]/);
To this:
tmp = content.match(/of:[\n]([^\r\n]*)[\r\n]/);
Thanks Kevin, I think I must have changed it while debugging.
The problem was with my regexp in the end. After a bit of trial and error the following worked:
tmp = content.match(/of:[\r\n]+([^\r\n]+)/);

Ember.js: How to get an array of model IDs from a corresponding array of model attributes

For a Tag model that I have in Ember-Data, I have 4 records in my store:
Tags:
id tag_name
1 Writing
2 Reading-Comprehension
3 Biology
4 Chemistry
In my code I have an array of tag_names, and I want to get a corresponding array of tag IDs. I'm having 2 problems:
My server is being queried even though I have these tags in my store. When I call store.find('tag', {tag_name: tag_name}), I didn't expect to need a call to the server. Here is all the code I'm using to attempt to create an array of IDs.
var self = this;
var tagsArray = ["Writing", "Reading-Comprehension", "Chemistry"];
var tagIdArr = []
tagsArray.forEach(function(tag_name) {
return self.store.find('tag', { tag_name: tag_name }).then(function(tag) {
tagIdArr.pushObject(tag.get('content').get('0').get('id'));
})
})
return tagIdArr;
When I console.log the output of the above code gives me an empty array object with length 0. Clicking on the caret next to the empty array shows three key-value pairs with the correct data. But the array is empty. I'm sure there is a simple explanation for this behavior, but I'm not sure why this is. I've used code similar to the above in other places successfully.
Find hits the server, but peek does not.
var tagsArray = ["Writing", "Reading-Comprehension", "Chemistry"];
return this.store.peekAll('tag').filter(function(tag){
return tagsArray.indexOf(tag) !== -1;
}).mapBy('id');
See: http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_reorganized-find-methods