You need to sign in to do that
Don't have an account?
Edgars Everts 5
How to inspect lightning:datatable getParam( <parameter> )?
Hi,
Story about lightning:datatable
some component lines:
attributes:
Table definition:
and modal window ( to simulate dropdown list )
with picklist values:
on Closing modal window with save
controller lines:
console output:
action: openModal => row: [object Object]
Console output:
Load Opportunitties with lightning datatable
OnRowaction - do open Modal window, here store current Row in component variable.
On Modal window picklist value change, store picklist value in component variable
On Modal window close by Save , get Component Row and Component Table, and find the Position of Row in Table
Then idea is set Row.fieldName = to Modal Window picklist value
And on Save Table, should Update Opportunities accordingly.
Have to admit that this "solution" works in developer edition, but have challenge to transfer code to "work-sandbox".
Copy paste 1:1, but in "work-sanbox" it doesn't work.
And page fails with the following:
This page has an error. You might just need to refresh it. Action failed: c:opportunityDataTableTest$controller$saveSegment [Cannot set property 'StageName' of undefined] Failing descriptor: {c:opportunityDataTableTest$controller$saveSegment}
Question:?
In code examples on RowActions there is variable row, which is get by event.getParam(<param>).
e.g.
Honestly not clear where this 'row' parameter comes from as per lightning:datatable there is no such parameter. Any ideas?
How to ensure what parameters can be used in event.getParam( ) function?
Seems that Object position cannot be found by "row" , and indexOf returns -1. / but in developer org, the "same" code works/
Any ideas how to debug this besides console.log?
Is it possible to compare the data types of row [Object] and v.data[index][Object]?
Looking forward for your advice!
Thank you in advance.
Kind regards,
Edgars
Story about lightning:datatable
some component lines:
attributes:
<aura:attribute name="data" type="Object"/> <aura:attribute name="rowSource" type="Object"/>
Table definition:
<lightning:datatable aura:id="linesTable" keyField="Id" columns="{! v.columns }" data="{! v.data }" errors="{! v.errors }" draftValues="{! v.draftValues }" selectedRows="{! v.selectedRows }" showRowNumberColumn="true" onrowaction="{! c.openModel }" onrowselection="{! c.countRows }" onsave="{! c.handleSaveEdition }" />
and modal window ( to simulate dropdown list )
with picklist values:
<lightning:select aura:id="selectedStage" label="" name="selectStage" onchange="{!c.handleStageSelected}"> <option value=""> </option>
on Closing modal window with save
<lightning:button variant="brand" label="Save" title="Save" onclick="{!c.saveSegment}"/>
controller lines:
openModel: function(component, event, helper) { component.set("v.isOpen", true); console.log("action: openModal => row: " + event.getParam('row')); component.set("v.rowSource", event.getParam('row')); },
console output:
action: openModal => row: [object Object]
saveSegment: function(component, event, helper) { // and set set the "isOpen" attribute to "False for close the model Box. component.set("v.isOpen", false); var vStageName = component.get("v.selectedStage"); var cmRow = component.get("v.rowSource"); console.log("action: saveSegment => row: " + cmRow); var cmRows = component.get("v.data"); console.log("action: saveSegment => rows: " + cmRows); /** This method has the same algorithm as Array.prototype.indexOf(). TypedArray is one of the typed array types here. */ var cmRowPosition = cmRows.indexOf(cmRow); console.log("action: saveSegment => rowIndex: " + cmRowPosition); cmRows[cmRowPosition].StageName = vStageName; component.set("v.draftValues", cmRows); },
Console output:
action: openModal => row: [object Object] opportunityDataTableTest.js:44 action: saveSegment => row: [object Object] opportunityDataTableTest.js:46 action: saveSegment => rows: [object Object],[object Object],[object Object],[object Object],[object Object] opportunityDataTableTest.js:50 action: saveSegment => rowIndex: -1Scenario:
Load Opportunitties with lightning datatable
OnRowaction - do open Modal window, here store current Row in component variable.
On Modal window picklist value change, store picklist value in component variable
On Modal window close by Save , get Component Row and Component Table, and find the Position of Row in Table
Then idea is set Row.fieldName = to Modal Window picklist value
And on Save Table, should Update Opportunities accordingly.
Have to admit that this "solution" works in developer edition, but have challenge to transfer code to "work-sandbox".
Copy paste 1:1, but in "work-sanbox" it doesn't work.
And page fails with the following:
This page has an error. You might just need to refresh it. Action failed: c:opportunityDataTableTest$controller$saveSegment [Cannot set property 'StageName' of undefined] Failing descriptor: {c:opportunityDataTableTest$controller$saveSegment}
Question:?
In code examples on RowActions there is variable row, which is get by event.getParam(<param>).
e.g.
component.set("v.rowSource", event.getParam('row'));
Honestly not clear where this 'row' parameter comes from as per lightning:datatable there is no such parameter. Any ideas?
How to ensure what parameters can be used in event.getParam( ) function?
Seems that Object position cannot be found by "row" , and indexOf returns -1. / but in developer org, the "same" code works/
Any ideas how to debug this besides console.log?
Is it possible to compare the data types of row [Object] and v.data[index][Object]?
Looking forward for your advice!
Thank you in advance.
Kind regards,
Edgars
Thanks goes to Aleksejs J. who did porpose to use any other method to calculate rowIndex value.
That's all the magic. Not sure if this is according to best practice, but it works.
Enjoy IT.
All Answers
and here is the console output from developer edition:
Where custom object Expense__c is used instead of Opportunities ...
and component has the same attribute definition ( type = Object )
How to ensure what parameters can be used in event.getParam( ) function?"
console output:
So datatable:lightning onrowaction event has at least "row" Parameter. Enjoy It.
Thanks goes to Aleksejs J. who did porpose to use any other method to calculate rowIndex value.
That's all the magic. Not sure if this is according to best practice, but it works.
Enjoy IT.