4

So say I am have an <apex:dataTable> with multiple jobs. Each job will have a start and end time. For each line of the dataTable, I have a link to open a JQuery dialog (a complex one). And I need to pass the data (including job Id, start and end time) to the JQuery dialog.

The question is, should I just put the Id of the job into the attribute of the link and pass minimum data, and use javascript remote action to retrieve the data based on requirement, or should I be writing all the info into the link's attribute and pass all of them to the dialog?

Approach 1 will be costing more loading time and heap size, I am not sure how bad is that. Approach 2 will definitely be causing more dialog open time. And plus, since the start and end time are not written into any DOM object, I need a global variable to store them which is kind of evil. What is the best approach in this?

  • 2
    Storing un-rendered data in the page (e.g. via .data in jquery) shouldn't really be considered evil... it sure beats the heck out of having to call back to a server just to get a few bytes of data you knew about at page request time! I second Daniel's answer. I would only call back to the server if pre-loading would mean megs of unused data per request. – jkraybill Apr 28 '15 at 6:08
6

I usually go ahead and load them into the DOM when I load the page and then pass them on. I use the html5 data elements to store things that aren't going to be displayed but are needed by JavaScript.

If you are already using jQuery, then it is easy to get the html5 data values.

var tr = j$(this).closest('tr');
var startTime = tr.data('startTime')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.