Why without the JSON.parse method, I can't sort the data in lightning-datatable?Lightning Web Component - Sort table columnsJavaScript executing before controller method finishesWhy Lightning Web Componentlightning-tree-grid link to js function?Fetching data from Apex controller for lightning web componentIs it not possible to get a parent field in a datatable column specification, for a Lightning Web Component?Lightning Web Components inline editing Datatable - data update issueLightning Web Components lightning-datatable detect “select all” checkboxIssue while iterating lightning-tab, as expressions can't be usedLWC datatable column with a lightning-card insideHow to display lable to a url cell in LWC datatable?
How do you say “buy” in the sense of “believe”?
What are the benefits of cryosleep?
Plot twist where the antagonist wins
Approximate solution : factorial and exponentials
When do characters level up?
What is the difference between nullifying your vote and not going to vote at all?
Under what law can the U.S. arrest International Criminal Court (ICC) judges over war crimes probe?
Canon 70D often overexposing or underexposing shots
Seed ship, unsexed person, cover has golden person attached to ship by umbilical cord
Can a wire having 610-670 THz (frequency of blue light) A.C frequency supply, generate blue light?
Does this degree 12 genus 1 curve have only one point over infinitely many finite fields?
Is there a public standard for 8 and 10 character grid locators?
Why does the 6502 have the BIT instruction?
What do different value notes on the same line mean?
General purpose replacement for enum with FlagsAttribute
Would jet fuel for an F-16 or F-35 be producible during WW2?
Employer demanding to see degree after poor code review
Why colon to denote that a value belongs to a type?
Is there a way to make it so the cursor is included when I prtscr key?
Windows 10 Programs start without visual Interface
How strong are Wi-Fi signals?
What's the Difference between Two Single-Quotes and One Double-Quote?
How long does it take to crack RSA 1024 with a PC?
Forward and backward integration -- cause of errors
Why without the JSON.parse method, I can't sort the data in lightning-datatable?
Lightning Web Component - Sort table columnsJavaScript executing before controller method finishesWhy Lightning Web Componentlightning-tree-grid link to js function?Fetching data from Apex controller for lightning web componentIs it not possible to get a parent field in a datatable column specification, for a Lightning Web Component?Lightning Web Components inline editing Datatable - data update issueLightning Web Components lightning-datatable detect “select all” checkboxIssue while iterating lightning-tab, as expressions can't be usedLWC datatable column with a lightning-card insideHow to display lable to a url cell in LWC datatable?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'd like to understand the usefulness of the method JSON.parse in the JS file of a lwc when we want to perform certain actions on a list of objects retrieved from our apex controller. I give you an example.
I have implemented the sorting functionality on a lightning datatable in a lwc. but my problem is when I don't use the JSON.parse method when I get all the data, I get an empty proxy. Here is the the output when I'm debugging:
But when I use the JSON.parse method when I get the data I want to sort, I get and I see all the data when I'm debugging. Here is the output for this case:
Can someone help me please to understand why we can't see the data without the JSON.pase method and why without the JSON.parse method it doesn't work?
here is the html template:
<lightning-datatable key-field="Id"
data=opportunities
columns=columns
onsort=updateColumnSorting
sorted-by=sortedBy
sorted-direction=sortedDirection>
</lightning-datatable>
the js file:
import LightningElement ,wire,track from 'lwc';
import getAllOpps from '@salesforce/apex/GetAllOpportunities.getAllOpps';
export default class OpportunityList extends LightningElement
@track columns = [
label: 'Opportunity name',
fieldName: 'Name',
type: 'tex',
sortable: true
,
label: 'Stage Name',
fieldName: 'StageName',
type: 'text',
sortable: true
,
label: 'Close date',
fieldName: 'CloseDate',
type: 'date',
sortable: true
];
@track error;
@track opportunities = [];
@track sortedBy;
@track sortedDirection = 'asc';
@wire(getAllOpps)
wiredOpps(error,data)
if (data)
this.opportunities = data;
this.error = undefined;
else if (error)
this.error = error;
this.opportunities = undefined;
sortData(fieldName, sortDirection)
//let data = JSON.parse(JSON.stringify(this.opportunities));
let data = this.opportunities;
//function to return the value stored in the field
const key = (a) =>
let fieldValue = a[fieldName] ? (typeof a[fieldName] === 'string' ? a[fieldName].toLowerCase() : a[fieldName]) : '';
return fieldValue;
let reverse = sortDirection === 'asc' ? 1: -1;
//set sorted data to opportunities attribute
this.opportunities = data.sort((a,b) =>
return reverse * ((key(a) > key(b)) - (key(b) > key(a)));
);
updateColumnSorting(event)
this.sortedBy = event.detail.fieldName;
this.sortedDirection = event.detail.sortDirection;
this.sortData(this.sortedBy,this.sortedDirection);
And the apex controller:
public with sharing class GetAllOpportunities
@AuraEnabled(cacheable=true)
public static List<Opportunity> getAllOpps()
return [SELECT Id, Name ,StageName, CloseDate FROM Opportunity Limit 10];
Thanks in advance!
javascript lightning-web-components
New contributor
add a comment |
I'd like to understand the usefulness of the method JSON.parse in the JS file of a lwc when we want to perform certain actions on a list of objects retrieved from our apex controller. I give you an example.
I have implemented the sorting functionality on a lightning datatable in a lwc. but my problem is when I don't use the JSON.parse method when I get all the data, I get an empty proxy. Here is the the output when I'm debugging:
But when I use the JSON.parse method when I get the data I want to sort, I get and I see all the data when I'm debugging. Here is the output for this case:
Can someone help me please to understand why we can't see the data without the JSON.pase method and why without the JSON.parse method it doesn't work?
here is the html template:
<lightning-datatable key-field="Id"
data=opportunities
columns=columns
onsort=updateColumnSorting
sorted-by=sortedBy
sorted-direction=sortedDirection>
</lightning-datatable>
the js file:
import LightningElement ,wire,track from 'lwc';
import getAllOpps from '@salesforce/apex/GetAllOpportunities.getAllOpps';
export default class OpportunityList extends LightningElement
@track columns = [
label: 'Opportunity name',
fieldName: 'Name',
type: 'tex',
sortable: true
,
label: 'Stage Name',
fieldName: 'StageName',
type: 'text',
sortable: true
,
label: 'Close date',
fieldName: 'CloseDate',
type: 'date',
sortable: true
];
@track error;
@track opportunities = [];
@track sortedBy;
@track sortedDirection = 'asc';
@wire(getAllOpps)
wiredOpps(error,data)
if (data)
this.opportunities = data;
this.error = undefined;
else if (error)
this.error = error;
this.opportunities = undefined;
sortData(fieldName, sortDirection)
//let data = JSON.parse(JSON.stringify(this.opportunities));
let data = this.opportunities;
//function to return the value stored in the field
const key = (a) =>
let fieldValue = a[fieldName] ? (typeof a[fieldName] === 'string' ? a[fieldName].toLowerCase() : a[fieldName]) : '';
return fieldValue;
let reverse = sortDirection === 'asc' ? 1: -1;
//set sorted data to opportunities attribute
this.opportunities = data.sort((a,b) =>
return reverse * ((key(a) > key(b)) - (key(b) > key(a)));
);
updateColumnSorting(event)
this.sortedBy = event.detail.fieldName;
this.sortedDirection = event.detail.sortDirection;
this.sortData(this.sortedBy,this.sortedDirection);
And the apex controller:
public with sharing class GetAllOpportunities
@AuraEnabled(cacheable=true)
public static List<Opportunity> getAllOpps()
return [SELECT Id, Name ,StageName, CloseDate FROM Opportunity Limit 10];
Thanks in advance!
javascript lightning-web-components
New contributor
add a comment |
I'd like to understand the usefulness of the method JSON.parse in the JS file of a lwc when we want to perform certain actions on a list of objects retrieved from our apex controller. I give you an example.
I have implemented the sorting functionality on a lightning datatable in a lwc. but my problem is when I don't use the JSON.parse method when I get all the data, I get an empty proxy. Here is the the output when I'm debugging:
But when I use the JSON.parse method when I get the data I want to sort, I get and I see all the data when I'm debugging. Here is the output for this case:
Can someone help me please to understand why we can't see the data without the JSON.pase method and why without the JSON.parse method it doesn't work?
here is the html template:
<lightning-datatable key-field="Id"
data=opportunities
columns=columns
onsort=updateColumnSorting
sorted-by=sortedBy
sorted-direction=sortedDirection>
</lightning-datatable>
the js file:
import LightningElement ,wire,track from 'lwc';
import getAllOpps from '@salesforce/apex/GetAllOpportunities.getAllOpps';
export default class OpportunityList extends LightningElement
@track columns = [
label: 'Opportunity name',
fieldName: 'Name',
type: 'tex',
sortable: true
,
label: 'Stage Name',
fieldName: 'StageName',
type: 'text',
sortable: true
,
label: 'Close date',
fieldName: 'CloseDate',
type: 'date',
sortable: true
];
@track error;
@track opportunities = [];
@track sortedBy;
@track sortedDirection = 'asc';
@wire(getAllOpps)
wiredOpps(error,data)
if (data)
this.opportunities = data;
this.error = undefined;
else if (error)
this.error = error;
this.opportunities = undefined;
sortData(fieldName, sortDirection)
//let data = JSON.parse(JSON.stringify(this.opportunities));
let data = this.opportunities;
//function to return the value stored in the field
const key = (a) =>
let fieldValue = a[fieldName] ? (typeof a[fieldName] === 'string' ? a[fieldName].toLowerCase() : a[fieldName]) : '';
return fieldValue;
let reverse = sortDirection === 'asc' ? 1: -1;
//set sorted data to opportunities attribute
this.opportunities = data.sort((a,b) =>
return reverse * ((key(a) > key(b)) - (key(b) > key(a)));
);
updateColumnSorting(event)
this.sortedBy = event.detail.fieldName;
this.sortedDirection = event.detail.sortDirection;
this.sortData(this.sortedBy,this.sortedDirection);
And the apex controller:
public with sharing class GetAllOpportunities
@AuraEnabled(cacheable=true)
public static List<Opportunity> getAllOpps()
return [SELECT Id, Name ,StageName, CloseDate FROM Opportunity Limit 10];
Thanks in advance!
javascript lightning-web-components
New contributor
I'd like to understand the usefulness of the method JSON.parse in the JS file of a lwc when we want to perform certain actions on a list of objects retrieved from our apex controller. I give you an example.
I have implemented the sorting functionality on a lightning datatable in a lwc. but my problem is when I don't use the JSON.parse method when I get all the data, I get an empty proxy. Here is the the output when I'm debugging:
But when I use the JSON.parse method when I get the data I want to sort, I get and I see all the data when I'm debugging. Here is the output for this case:
Can someone help me please to understand why we can't see the data without the JSON.pase method and why without the JSON.parse method it doesn't work?
here is the html template:
<lightning-datatable key-field="Id"
data=opportunities
columns=columns
onsort=updateColumnSorting
sorted-by=sortedBy
sorted-direction=sortedDirection>
</lightning-datatable>
the js file:
import LightningElement ,wire,track from 'lwc';
import getAllOpps from '@salesforce/apex/GetAllOpportunities.getAllOpps';
export default class OpportunityList extends LightningElement
@track columns = [
label: 'Opportunity name',
fieldName: 'Name',
type: 'tex',
sortable: true
,
label: 'Stage Name',
fieldName: 'StageName',
type: 'text',
sortable: true
,
label: 'Close date',
fieldName: 'CloseDate',
type: 'date',
sortable: true
];
@track error;
@track opportunities = [];
@track sortedBy;
@track sortedDirection = 'asc';
@wire(getAllOpps)
wiredOpps(error,data)
if (data)
this.opportunities = data;
this.error = undefined;
else if (error)
this.error = error;
this.opportunities = undefined;
sortData(fieldName, sortDirection)
//let data = JSON.parse(JSON.stringify(this.opportunities));
let data = this.opportunities;
//function to return the value stored in the field
const key = (a) =>
let fieldValue = a[fieldName] ? (typeof a[fieldName] === 'string' ? a[fieldName].toLowerCase() : a[fieldName]) : '';
return fieldValue;
let reverse = sortDirection === 'asc' ? 1: -1;
//set sorted data to opportunities attribute
this.opportunities = data.sort((a,b) =>
return reverse * ((key(a) > key(b)) - (key(b) > key(a)));
);
updateColumnSorting(event)
this.sortedBy = event.detail.fieldName;
this.sortedDirection = event.detail.sortDirection;
this.sortData(this.sortedBy,this.sortedDirection);
And the apex controller:
public with sharing class GetAllOpportunities
@AuraEnabled(cacheable=true)
public static List<Opportunity> getAllOpps()
return [SELECT Id, Name ,StageName, CloseDate FROM Opportunity Limit 10];
Thanks in advance!
javascript lightning-web-components
javascript lightning-web-components
New contributor
New contributor
edited 4 hours ago
Mohith Shrivastava
62.3k7106150
62.3k7106150
New contributor
asked 8 hours ago
dibocordibocor
237
237
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The behavior you are seeing is because of Salesforce feature called lightning locker.
Any object in lwc JavaScript will use the proxy object.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_proxy.htm
It's a security feature that makes debugging difficult but adds additional security.
You don't need to use JSON.stringify and JSON.parse in prod .You can use it for debugging purposes.
Update
Looking into the code , it looks like lockerservice proxy is forcing the object to readonly on datatable . You should report this as a bug to salesforce .
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
1
I edited the question and added the code
– dibocor
6 hours ago
1
ok I added the apex class
– dibocor
6 hours ago
|
show 4 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
dibocor is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f263740%2fwhy-without-the-json-parse-method-i-cant-sort-the-data-in-lightning-datatable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The behavior you are seeing is because of Salesforce feature called lightning locker.
Any object in lwc JavaScript will use the proxy object.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_proxy.htm
It's a security feature that makes debugging difficult but adds additional security.
You don't need to use JSON.stringify and JSON.parse in prod .You can use it for debugging purposes.
Update
Looking into the code , it looks like lockerservice proxy is forcing the object to readonly on datatable . You should report this as a bug to salesforce .
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
1
I edited the question and added the code
– dibocor
6 hours ago
1
ok I added the apex class
– dibocor
6 hours ago
|
show 4 more comments
The behavior you are seeing is because of Salesforce feature called lightning locker.
Any object in lwc JavaScript will use the proxy object.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_proxy.htm
It's a security feature that makes debugging difficult but adds additional security.
You don't need to use JSON.stringify and JSON.parse in prod .You can use it for debugging purposes.
Update
Looking into the code , it looks like lockerservice proxy is forcing the object to readonly on datatable . You should report this as a bug to salesforce .
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
1
I edited the question and added the code
– dibocor
6 hours ago
1
ok I added the apex class
– dibocor
6 hours ago
|
show 4 more comments
The behavior you are seeing is because of Salesforce feature called lightning locker.
Any object in lwc JavaScript will use the proxy object.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_proxy.htm
It's a security feature that makes debugging difficult but adds additional security.
You don't need to use JSON.stringify and JSON.parse in prod .You can use it for debugging purposes.
Update
Looking into the code , it looks like lockerservice proxy is forcing the object to readonly on datatable . You should report this as a bug to salesforce .
The behavior you are seeing is because of Salesforce feature called lightning locker.
Any object in lwc JavaScript will use the proxy object.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_proxy.htm
It's a security feature that makes debugging difficult but adds additional security.
You don't need to use JSON.stringify and JSON.parse in prod .You can use it for debugging purposes.
Update
Looking into the code , it looks like lockerservice proxy is forcing the object to readonly on datatable . You should report this as a bug to salesforce .
edited 5 hours ago
answered 7 hours ago
Mohith ShrivastavaMohith Shrivastava
62.3k7106150
62.3k7106150
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
1
I edited the question and added the code
– dibocor
6 hours ago
1
ok I added the apex class
– dibocor
6 hours ago
|
show 4 more comments
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
1
I edited the question and added the code
– dibocor
6 hours ago
1
ok I added the apex class
– dibocor
6 hours ago
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
Thank you @Mohith Shrivastava for your reply. But is it normal to get a proxy with an empty array?
– dibocor
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
No that's not normal.Do you see the data on the UI ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
Can you share the code snippet so we can see what's going on ?
– Mohith Shrivastava
7 hours ago
1
1
I edited the question and added the code
– dibocor
6 hours ago
I edited the question and added the code
– dibocor
6 hours ago
1
1
ok I added the apex class
– dibocor
6 hours ago
ok I added the apex class
– dibocor
6 hours ago
|
show 4 more comments
dibocor is a new contributor. Be nice, and check out our Code of Conduct.
dibocor is a new contributor. Be nice, and check out our Code of Conduct.
dibocor is a new contributor. Be nice, and check out our Code of Conduct.
dibocor is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f263740%2fwhy-without-the-json-parse-method-i-cant-sort-the-data-in-lightning-datatable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown