I have created controller and visual force pages using handson table grid format. If I change the any record in the grid it update in related object. My controller and class working fine but not the update in related object please find the below images.
Controller:
global without sharing class OpportunityLineItemController{ public OpportunityLineItemController(ApexPages.StandardController controller){ } public String OpportunityLineItem { get; set; } public string volumeJSON {get;set;}
// Constructor
public OpportunityLineItemController(){
}
public void OpportunityLineItemList(){
for(OpportunityLineItem oli: [select id, ListPrice,Name,TotalPrice,UnitPrice from OpportunityLineItem order by name]) {
Map<String,Object> Volume = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(oli));
if (String.isBlank(volumeJSON) ) volumeJSON = '[' + JSON.serialize(Volume);
else volumeJSON = volumeJSON + ',' + JSON.serialize(Volume);
}
volumeJSON = volumeJSON + ']';
}
@RemoteAction
public static List<OpportunityLineItem> Save(String OLIJSON) {
List<String> valuefromJS=new List<String>();
OLIJSON= OLIJSON.remove('[');
OLIJSON = OLIJSON.remove(']');
OLIJSON= OLIJSON.replace('},{','}SPLIT{');
valuefromJS = OLIJSON.split('SPLIT');
List<OpportunityLineItem> volSave = new List<OpportunityLineItem>();
for(Integer i=0; i<valuefromJS.size(); i++){
OpportunityLineItem v=(OpportunityLineItem) JSON.deserialize(valuefromJS[i], OpportunityLineItem.class);
volSave.add(v);
}
update volSave;
return null;
}
}
<apex:page Standardcontroller="Opportunity" extensions="OpportunityLineItemController" action="{!OpportunityLineItemList}"> <apex:form > <apex:pageblock > <head> <!-- Handsontable library code --> <script src="{!URLFOR($Resource.excelgrid,'handsontable/js/jquery-1.11.1.min.js')}" language="JavaScript" type="text/javascript"></script> <script src="{!URLFOR($Resource.excelgrid,'handsontable/js/handsontable.full.js')}" language="JavaScript" type="text/javascript"></script> <link rel="stylesheet" href="{!URLFOR($Resource.excelgrid,'handsontable/css/handsontable.full.css')}" type="text/css" charset="utf-8" /> <link rel="stylesheet" href="{!URLFOR($Resource.excelgrid,'handsontable/css/samples.css')}" type="text/css" charset="utf-8" /> <script type="text/javascript"> var changedData; $(document).ready(function () { var data = {!volumeJSON} , container = document.getElementById('volumes'), hot; hot = new Handsontable(container, { data: data, minSpareRows: 0, colHeaders: true, contextMenu: true, maxRows: data.numberOfRows, colHeaders: ['Model','Version','Discount','Volumes'], columns: [ {data: 'Name', type: 'numeric'}, {data: 'ListPrice', type: 'numeric'}, {data: 'TotalPrice', type : 'numeric'}, {data: 'UnitPrice ', type: 'numeric'}, ], contextMenu: ['undo', 'redo'] , afterChange: function (change, source) { if(source == 'edit'){ OpportunityLineItemController.Save(JSON.stringify(data), function(results, event){ if(event.status) { alert('success'); } else { alert(event.status); } }); } } }); }); </script> </head> <body> <div class="handsontable" id="volumes"></div> </body>