Having an issue getting the Record Ids of the selected record in Lightning Datatable.
Here is my controller
<!-- attributes -->
<aura:attribute name="dataArr" type="String[]"/>
<aura:attribute name="data" type="Object"/>
<aura:attribute name="columnsStr" type="String"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="maxRowSelection" type="Integer" default="1"/>
<aura:attribute name="numOfRowsSelected" type="Integer" default="0"/>
<aura:attribute name="key" type="String" default="Id"/>
<aura:attribute name="recordId" type="String" />
<aura:attribute name="recordIds" type="String" />
<!-- handlers-->
<aura:handler name="init" value="{!this }" action="{! c.doInit }"/>
<div style="height: 300px">
<lightning:datatable keyField="{!v.key}"
data="{! v.data }"
columns="{! v.columns }"
maxRowSelection="{! v.maxRowSelection }"
onrowselection="{! c.setRecordId }"
/>
</div>
and here is my setRecordId function
setRecordId : function(component, event, helper){
var selectedRows = event.getParam('selectedRows');
var key = component.get('v.key');
var recIds = '';
console.log(selectedRows);
if(selectedRows){
if(selectedRows.length === 1){
console.log(selectedRows.id)
console.log(selectedRows[key])
console.log(selectedRows[0][key])
component.set('v.recordId', selectedRows[0][key]);
}
else{
for(let i = 0; i < selectedRows.length; i++){
recIds += selectedRows[i][key] + ',';
}
component.set('v.recordIds', recIds);
component.set('v.numOfRowsSelected', selectedRows.length);
}
}
},
Var selectedRows returns the correct selected row as an object within an array but i can't seem to find the correct syntax to access that records ID for some reason. Let me know if any additional information is needed here.
appreciate the help
You will have to iterate over the selected rows in a for-loop and you can then get the id references -
Something like -
for(var i=0; i<selectedRows.length; i++){
//This will give you the entire data for the row
console.log(selectedRows[i]);
//You can now fetch its Id as well as other parameters
...
}
Related
Hi I'm new to salesforce. I'm trying to develop a lightning component that will take user input, process that input & will display the value in two text box.My lightning component looks like
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable" access="global" controller="VisionController">
<!--Remember to define your binding attribute-->
<aura:attribute name="val" type="String"/>
<lightning:card title="Partner Information">
<div class="slds-p-around_medium">
<p>
<!--Set you attribute as the value of the lightning:input component-->
<lightning:input aura:name="val"
label ="Enter KPI"
value="{!v.val}"
type="text"
onchange="{!c.onChange}"/>
</p>
</div>
</lightning:card>
My JS controller looks like
({
onChange : function(component, event, helper) {
var action = component.get("c.getCallKPI")
action.setParams({
"value":val,
})
$A.enqueueAction(action)
}
})
I tried to do the iteration portion in controller using following code
var prediction=component.find("pred")
var predictionProb=component.find("predProb")
<aura:iteration items="{c.getCallKPI}" var="predUrl" >
prediction.value="{!predUrl.label}"
predictionProb.value="{!prediction.probability}"
</aura:iteration>
where prediction & predictionProb are id of two lightning inputs given in my component.But I'm getting syntax error at </aura:iteration>
If I'm doing it in component using following code
<aura:iteration items="{c.getCallKPI}" var="predUrl" >
<lightning:input id="pred" readonly="true" value="{!predUrl.label}"/>
<lightning:input id="predProb" readonly="true" value="{!predUrl.probability}" />
</aura:iteration>
Then it's not giving any error but not populating the inputs.
Can you guide how do I resolve this?
my getCallKPI is given below
#auraEnabled
public static List<KPI.Prediction> getCallKPI(string value) {
return KPI.Prediction;
}
You should use aura:iteration inside component markup.
In your component create new attribute of type "List".
<aura:attribute name="predictions" type="List"/>
In JS controller specify callback for action, in which set new attribute to response.getReturnValue().
action.setCallback(this, function(response) {
component.set("v.predictions", response.getReturnValue());
}
Calling a Server-Side Action
Inside component, iterate over returned records:
<aura:iteration items="{!v.predictions}" var="item">
//your logic
</aura:iteration>
aura:iteration
I am trying to make a picklist dependent on another one
Controller picklist:Subtype
Dependent picklist
I succeded to do this
I put it in a lightning component
<ui:inputSelect aura:id="conType" label="Type" class="slds-select" change="{!c.onControllerFieldChange}" value="{!v.TypeV}">
<ui:inputSelect aura:id="conSubtype" label="Sub Type" value="{!v.SubTypeV}" disabled="{!v.isDependentDisable}" class="slds-select" />
I put this component from another lightning component
DependentSubtype is the child component
TypeV child component attribute to initialize the value of controller picklist (Type)
SubTypeV child component attribute to initialize the value of dependent picklist (SubType)
For the Controller picklist (Type) the initialization works
But for the dependent picklis (Subtype) it doesn't
Thanks in advance
It seems that your approach is right, however, its difficult to point out the problem from just that two lines of code. Here is a approach for dependent picklist,
// controller.js
({
doInit : function(component, event, helper) {
helper.loadOption1(component, event);
},
changeSecondPicklist : function(component, event, helper) {
helper.populateOption2(component, event);
}
})
// helper.js
({
loadOption1 : function(component, event) {
var option = [];
option.push('Type1.1');
option.push('Type1.2');
option.push('Type1.3');
component.set('v.option1', option);
},
populateOption2 : function(component, event) {
var value = event.getParam('value');
var option = [];
if (value == 'Type1.1') {
option.push('SubType1.1');
option.push('SubType1.2');
option.push('SubType1.3');
}
else if (value == 'Type1.2') {
option.push('SubType2.1');
option.push('SubType2.2');
option.push('SubType2.3');
}
else {
option.push('SubType3.1');
option.push('SubType3.2');
option.push('SubType3.3');
}
component.set('v.option2', option);
}
})
<!-- lightning component -->
<aura:component>
<aura:attribute name="option1" type="String[]" />
<aura:attribute name="option2" type="String[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<lightning:select name="select1" label="Type" required="true" onchange="{!c.changeSecondPicklist}">
<option value="">choose one...</option>
<aura:iteration items="{!v.option1}" var="item">
<option value="{!item}">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:select name="select2" label="SubType" required="true">
<option value="">choose one...</option>
<aura:iteration items="{!v.option2}" var="item">
<option value="{!item}">{!item}</option>
</aura:iteration>
</lightning:select>
</aura:component>
Here I have used lightning tag as Salesforce is going discontinue support for ui tags. The logic is onchange event of first picklist populates the options of dependent picklist.
I am not able to see my lightning component when trying to create a lighting tab. Something is wrong with one of the components -
I moved the component and tab using salesforce dx and when editing the component. I am getting below error. I seems like one of the component is throwing an error when i am trying to edit the record -
Error = Review all error messages below to correct your data.
You can only create lightning tabs for AuraDefinitionBundles containing a component that implements force:appHostable and has no required attributes without a default value. (Related field: Content)
Observation - When i remove the attribute from parent component and child component than its working and i am able to save the tab. Something is not correct with my component initiation.
Code in parent Component -
<aura:if isTrue="{!!v.customTab}">
<div aura:id="defaultTabContent" class="slds-show">
<c:ApiRequestFieldMapping custom="false" objectName="Credit_Report__c"/>
</div>
</aura:if>
<aura:if isTrue="{!v.customTab}">
<div aura:id="customTabContent" class="slds-hide">
<c:ApiRequestFieldMapping custom="true" listSObjects="
{!v.listSObjects}" message="Select object from drop-down."
messageClass="Info"/>
</div>
Code in Child Component -
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:registerEvent name="handleModelVisiblity" type="c:HandleModel"/>
<!-- attributes -->
<aura:attribute name="custom" type="Boolean"/>
<aura:attribute name="objectName" type="String"/>
<aura:attribute name="listSObjects" type="String[]"/>
<aura:attribute name="message" type="String"/>
<aura:attribute name="messageClass" type="String"/>
<aura:attribute name="listSObjectFields" type="String[]"
required="false"/>
<aura:attribute name="customObjectName" type="String"
required="false"/>
<aura:attribute name="listWrapper"
type="RequestMappingWrapper.MappingRecords[]" required="false"/>
Already Tried - 1. My component is already implementing "force:appHostable" interface.
2. The component us using latest version.(40.0)
3. Have already tried creating the components.
4. My org has my domain enabled and also have namespace.
I have fixed the issue. I have removed the reference to inner class in one of the attribute. Changed "RequestMappingWrapper.MappingRecords[]" to "RequestMappingWrapper[]".
HI guys I have two fields code and name I want to insert into the database the user inputs when they fill the form (I use a wizard)
.py
class cria_edita_recinto(osv.osv):
_name='cria.edita.recinto'
_description = 'Cria e Edita Recinto'
_rec_name='code'
_columns={
'code':fields.char("Código",size=10),
'name':fields.char("Designação",size=50)
}
_sql_constraints = [
('code', 'unique(code)', 'O codigo do recinto deve ser unico')
]
_order = 'code'
def insert_recinto(self,cr, uid,vals, context=None):
lista=vals.values()
code=lista[0]
cr.execute("INSERT INTO gs_recintos (code,name) VALUES (%s,'jt')" %(code))
return True
cria_edita_recinto()
.xml
<record model="ir.ui.view" id="cria_edita_recinto_form">
<field name="name">cria.edita.recinto.form</field>
<field name="model">cria.edita.recinto</field>
<field name="arch" type="xml">
<form string="cria edita recinto" version="7.0">
<group string=" ">
<field name="code"/>
<field name="name"/>
</group>
<footer>
<button name="insert_recinto" string="Configurar Pisos" type="object" class="oe_highlight"/>
ou
<button string="Cancelar" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
I have an image if you could help see here
http://help.openerp.com/question/46472/insert-into-database-the-input-fields/
In openerp 7 osv.osv is deprecated you may use orm.Model
Here the guide lines to write a good code for openerp.
the class that you have post is a module class, but if you would write a record with a wizard
you need to insert insert_recinto method inside a wizard class and not inside a model class.
after in your wizard insert_recinto method you may to write a data in with the orm method like as your_class_object.write(cr,uid,id,vals,context).
I resolved this problem....
<group string=" ">
<field name="code"/>
<field name="name"/>
<field name="nameBilhetes"/>
<field name="recinto_id" on_change="insert_piso(code,name,nameBilhetes,recinto_id)"/>
</group>
I use the on change method and on the .py i use
I query to insert into the Database.
Please mark this answer with the tick this solution resolve my problem
It's a pretty small problem but it's been bugging me for a while. Let's go with a very simplified example:
Store:
<ext:Store ID="myStore" runat="server" UseIdConfirmation="true">
<Reader>
<ext:JsonReader IDProperty="fieldId">
<Fields>
<ext:RecordField Name="myField" Type="String" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
Grid:
<ext:GridPanel ID="myGrid" runat="server" StoreID="myStore Width="200">
<ColumnModel>
<Columns>
<ext:Column ColumnID="myField" Header='My Field' DataIndex="myField" AutoDataBind="true" Width="180" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel2" runat="server" MoveEditorOnEnter="false" SingleSelect="true" />
</SelectionModel>
</ext:GridPanel>
For simplicity's sake, let's say I have the following inside a button's listener into the grid:
<Click Handler="changeRowValue(rowIndex, myGrid)" />
Javascript snippet:
var newValue = 'foo';
var changeRowValue = function(rowIndex, grd){
var store = grd.getStore();
store.getAt(rowIndex).set('myField', newValue);
}
This way, the store value is updated but it won't show 'foo' in the grid.
I know a simple
grd.view.refresh()
will update the grid, but it cleans the "dirt" and I'd like it dirty (that sounded nasty) to give the user feedback that the value hasn't been commited yet (you know, the small red arrow in the upper right corner).
This isn't a big deal in any extent and I know it can be done because I've done it before (I just can't remember where or how), so what's wrong here?
PS: I can't stress enough that this is a VERY simplified vision of the actual problem so there might be something in-between messing things up, but I find it to be very unlikely.
try using , myStore.reload();
function ,be sure u declare "onRead" function inside the store which reload the grid data
[
<ext:Store ID="myStore" runat="server" UseIdConfirmation="true" onRead="Load_Grid_Data">
<Reader>
<ext:JsonReader IDProperty="fieldId">
<Fields>
<ext:RecordField Name="myField" Type="String" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
var newValue = 'foo';
var changeRowValue = function(rowIndex, grd){
var store = grd.getStore();
store.getAt(rowIndex).set('myField', newValue);
store .reload();
}
and codebehind
protected void Load_Grid_Data (){//load grid}
]
whenever u call the reload function ,It triger onread function.