You need to sign in to do that
Don't have an account?
Ken Koellner
javascript remoting to fill pageblocktable and other tags in hybrid
I need to develop a page with a very large grid of data. I'm affraid it may exceed view state limits.
I know I could code it all in HTML with my choice of JS framework with JS remoting to get an write data. But that's is an increased coding effort and also loses the SF look and feel.
What I'd like to do instead of develop some sort of hybrid page. Use the VF tags like pageBlockTable column, etc. to get the SF look, but then on pageload have a script call javascript remote actions to get the full data which would be larger than 136K view state. Then have various onChange events save pieces of data back to SF via other remove actions. The only merge variable needed would be a master id to provide the intial script with a key so it could compose the calls to remote actions.
I wondering if maybe there could be some dummy empty tables and then a way to get scripts to fill them with data.
Anyone know if that architecture is doable and maybe have some examples anything like that?
I know I could code it all in HTML with my choice of JS framework with JS remoting to get an write data. But that's is an increased coding effort and also loses the SF look and feel.
What I'd like to do instead of develop some sort of hybrid page. Use the VF tags like pageBlockTable column, etc. to get the SF look, but then on pageload have a script call javascript remote actions to get the full data which would be larger than 136K view state. Then have various onChange events save pieces of data back to SF via other remove actions. The only merge variable needed would be a master id to provide the intial script with a key so it could compose the calls to remote actions.
I wondering if maybe there could be some dummy empty tables and then a way to get scripts to fill them with data.
Anyone know if that architecture is doable and maybe have some examples anything like that?
http://salesforce.stackexchange.com/questions/11825/display-javascript-result-in-a-pageblocktable
http://stackoverflow.com/questions/22887879/vf-pageblocktable-w-javascript-and-conditional-behavior
The first link is close. What it does is provide a way to create a vanilla HTML table that looks like a pageBlockTable because it uses the same styles. It doesn't behave like one as it doesn't have the highlighting JS on it. But it still doesn't look bad and may indeed be useful.
I considiered putting appropriate events on the rows to get the VF pageBlockTable highlighing. But SF doesn't consider it a good programming technique to call there routines. In any future release, if they change stuff, your page will break.
What I wanted to achieve
To be able to run a query to retreive a list of accounts using Javascript Remoting and display results in a pageblock table, in order take advantage of remoting's great speed.
The problem
The only solution involved having to inject the table into the page using script - I wanted a native pageblocktable right there in the DOM which I could just reRender to show the new results. Whilst other examples say to store results in an inputHidden component in order to pass it back to the controller, this doesn't work for lists because the variable is expecting a List<Account> but the component passes back a string even if you parse the JSON first.
The Solution
When you receive the results in the callback, put them into an apex:inputHidden field whos value points to a String apex variable whos setter immediately decodes the JSON and puts the list into a List<Account> variable. The pageblocktable uses that List<Account> variable, and when the script is finished, it calls an apex:actionFunction to reRender the table.
Positives
- Involves almost no script so the majority of the work is native apex and visualforce
- You're able to change the query without having to worry about updating a hard-coded injected table within your script
Negatives- You lose a lot of the increased speed that remoting provides so your results will not refresh much quicker than using completetly native code
End resultI actually ended up going down the html injection route after all due to its massively improved performance over either this hybrid method or the fully native method, but it was still a good exercise to find this solution which I've not seen offered up elsewhere.
Code
Apex
Visualforce Page and Script