0

We have a report where when users click on a particular row's dialog link, a modal dialog with additional details about that particular row appears. Currently, we do not load this data dynamically, and we had a reason for it before since we wanted the data in the dialogs to match the aggregated rows.

Turns out this data I'm pulling from a stored procedure I don't own takes many seconds to load (since it is calculated and not aggregated), and since it doesn't dynamically load dialog contents, it slowed down this report significantly since the data on the page is aggregated, but the data in the dialogs is not. IMO the data calls are the root cause and need fixed, but for the time being I'll have to move the loading time to when the dialogs are loaded with data.

I am hoping to dynamically load this content from here on, similar to here

However, since the dialog links I have also bring up a unique dialog to that clicked element, with contents retrieved from a DB for that particular link, I'm not sure I can simply do a .load() of a particular page without passing it what link was clicked, etc..

Current functionality:

HTML:

<c:if test="${seg.user.sbaEnabled && seg.sbaParamEnabled}">
    <c:set var="dialogcount" value="0" scope="page" />
    <c:forEach var="segment" items="${seg.dataList}">
        <c:set var="dialogcount" value="${dialogcount + 1}" scope="page"/>
        <div id="dialog<c:out value="${dialogcount}"/>" class="hidden" title="<spring:message code="perfseg.sbasegtitle"/> (<c:out value="${segment.segment}"/>)">
            <div class="theaddiv">
                <table class="reportingheader" style="width:100%;">
                    <thead>
                        <tr>
                            <th style="width:32%;">
                                <spring:message code="perfseg.sbasalesassociate"/>
                            </th>
                            <th style="width:10%;">
                                <spring:message code="perfseg.sbasales"/>
                            </th>
                            <th style="width:15%;">
                                <spring:message code="perfseg.sbapersales"/>
                            </th>
                            <th style="width:10%;">
                                <spring:message code="perfseg.sbatrans"/>
                            </th>                   
                            <th style="width:10%;">
                                <spring:message code="perfseg.sbaads"/>
                            </th>
                            <th style="width:10%;">
                                <spring:message code="perfseg.sbaupt"/>
                            </th>
                            <th style="width:10%;">
                                <spring:message code="perfseg.sbaspah"/>
                            </th>       
                            <!--Spacing for scrollbar alignment-->
                            <th style="width:3%;">
                                &nbsp;
                            </th>               
                        </tr>
                    </thead>                    
                </table>
            </div>
            <div class="tbodydiv" style="width: 100%;">
                <table class="reportingbody" style="width:100%;">
                    <tbody>
                        <c:forEach var="sba" items="${segment.sbaList}">
                            <tr>
                                <td style="width:32%">
                                    <c:if test="${sba.name ne 'Unassigned'}"><c:out value='${sba.name}'/></c:if>
                                    <c:if test="${sba.name eq 'Unassigned'}"><spring:message code="perfseg.sbaunassigned"/></c:if>
                                </td>
                                <td class="center" style="width:10%;">
                                    <fmt:formatNumber value='${sba.sales}' type="number"/>
                                </td>
                                <td class="center" style="width:15%;">
                                    <fmt:formatNumber value='${sba.percentSales}' type="number" minFractionDigits="1" maxFractionDigits="1"/>%
                                </td>
                                <td class="center" style="width:10%;">
                                    <fmt:formatNumber value='${sba.trans}' type="number"/>
                                </td>                   
                                <td class="center" style="width:10%;">
                                    <fmt:formatNumber value='${sba.ads}' type="number" minFractionDigits="2" maxFractionDigits="2"/>
                                </td>
                                <td class="center" style="width:10%;">
                                    <fmt:formatNumber value='${sba.upt}' type="number" minFractionDigits="2" maxFractionDigits="2"/>
                                </td>
                                <td class="center" style="width:10%;">
                                    <fmt:formatNumber value='${sba.spah}' type="number" minFractionDigits="2" maxFractionDigits="2"/>
                                </td>
                                <td style="width:3%;">
                                    &nbsp;
                                </td>                   
                            </tr>       
                        </c:forEach>                                                                                                                                                    
                    </tbody>                    
                </table>
            </div>
            <hr style="height:1px; border:none; color: #AAAAAA; background-color: #AAAAAA;"/>
        </div>
    </c:forEach>
    <div id="dialogbtnttl" class="hidden" title="<spring:message code="perfseg.sbadaytitle"/>">
        <div class="theaddiv">
            <div class="hidden center">
                <b class="infoTextBig"><spring:message code="perfseg.sbadaytitle"/></b>
                <br>
                    <div class="infoText">
                        <c:out value="${seg.brandName}"/> - <%=SystemConfig.getTranslatedTextByKey(LBIBOConstants.LANG_KEY_COMMON_TXTSTORE, userLocale)%> <c:out value="${seg.legacyStoreId}"/>
                    </div>
                <br>
                <%@ include file="../include/print_header.jsp" %>
                <br>
                <fmt:formatDate pattern="${seg.rptDateFormat}" value="${seg.transDate}" />
                <br>
                <br>
            </div>
            <table class="reportingheader" style="width:100%;">
                <thead>
                    <tr>
                        <th style="width:32%;">
                            <spring:message code="perfseg.sbasalesassociate"/>
                        </th>
                        <th style="width:10%;">
                            <spring:message code="perfseg.sbasales"/>
                        </th>
                        <th style="width:15%;">
                            <spring:message code="perfseg.sbapersales"/>
                        </th>
                        <th style="width:10%;">
                            <spring:message code="perfseg.sbatrans"/>
                        </th>                   
                        <th style="width:10%;">
                            <spring:message code="perfseg.sbaads"/>
                        </th>
                        <th style="width:10%;">
                            <spring:message code="perfseg.sbaupt"/>
                        </th>
                        <th style="width:10%;">
                            <spring:message code="perfseg.sbaspah"/>
                        </th>       
                        <!--Spacing for scrollbar alignment-->
                        <th style="width:3%;">
                            &nbsp;
                        </th>           
                    </tr>
                </thead>                    
            </table>
        </div>
        <div class="tbodybtndiv" style="width: 100%;">
            <table class="reportingbody" style="width:100%;">
                <tbody>
                    <c:forEach var="sbaTotal" items="${seg.sbaList}">
                        <tr>
                            <td style="width:32%">
                                <c:if test="${sbaTotal.name ne 'Unassigned'}"><c:out value='${sbaTotal.name}'/></c:if>
                                <c:if test="${sbaTotal.name eq 'Unassigned'}"><spring:message code="perfseg.sbaunassigned"/></c:if>
                            </td>
                            <td class="center" style="width:10%;">
                                <fmt:formatNumber value='${sbaTotal.sales}' type="number"/>
                            </td>
                            <td class="center" style="width:15%;">
                                <fmt:formatNumber value='${sbaTotal.percentSales}' type="number" minFractionDigits="1" maxFractionDigits="1"/>%
                            </td>
                            <td class="center" style="width:10%;">
                                <fmt:formatNumber value='${sbaTotal.trans}' type="number"/>
                            </td>                   
                            <td class="center" style="width:10%;">
                                <fmt:formatNumber value='${sbaTotal.ads}' type="number" minFractionDigits="2" maxFractionDigits="2"/>
                            </td>
                            <td class="center" style="width:10%;">
                                <fmt:formatNumber value='${sbaTotal.upt}' type="number" minFractionDigits="2" maxFractionDigits="2"/>
                            </td>
                            <td class="center" style="width:10%;">
                                <fmt:formatNumber value='${sbaTotal.spah}' type="number" minFractionDigits="2" maxFractionDigits="2"/>
                            </td>
                            <td style="width:3%;">
                                &nbsp;
                            </td>                   
                        </tr>    
                    </c:forEach>                                                                                                                                                                    
                </tbody>                    
            </table>
        </div>
    </div>

</c:if>

JS for links and dialogs:

$( "[id^=dialog]").dialog({
        width: 555,
        height: 315,
        autoOpen: false,
        resizable: false,
        modal: true,
        closeOnEscape: true        
    });

    $( "#dialogbtnttl").dialog({
        width: 555,
        height: 315,
        autoOpen: false,
        resizable: false,
        modal: true,
        buttons: dialogButtons,
        closeOnEscape: true        
    });

    // Link to open the dialog
    $( ".dialog-link" ).click(function() {
        //event.preventDefault();   

        var btnflag = $( this ).attr("data-btnflag");
        var seg = $( this ).attr( "data-seg" );

        if (btnflag == "false"){
            $( "#dialog"+seg ).removeClass("hidden");
            $( "#dialog"+seg ).dialog( "open" );
        }
        else {
            $( "#dialogbtnttl" ).removeClass( "hidden" );
            $( "#dialogbtnttl" ).dialog( "open" );
        }
    });

Does anyone have any advice in approaching this change I have to do? When loading, how can I load data unique to that particular report row?

Edit 1-

I was reading through the API for .load a bit more, and apparently we can pass some parameters which might help with uniquely identifying the row whose data is being requested, but I'm not sure how those parameters might be used/retrieved by the page itself that I'd have to create containing the dialog contents.

http://api.jquery.com/load/

At this point though, there may be some better solution I'm just not thinking of.

Community
  • 1
  • 1
aohm1989
  • 401
  • 1
  • 8
  • 19

1 Answers1

1

I have never used JQuery's load method. But I have done similar dynamic content loading (mostly in drop downs) using Web-service calls with the JQuery Ajax method to get the data I needed.

You could probably get the data using a web-service call with as many parameters as you need and then use load on the result to dynamically populate what you need.

Like I said I have never used the load method so I might be completely off on how it works, but that is just my two cents.

Edit: On another note the Ajax method runs asynchronously so you can be loading multiple sets of dynamic content through web-service calls at the same time.

Edit 2: As per discussion, here is the wrapper function for the standard JQuery Ajax function. To use it simply pass your method name as a string, parameters as an object (example: var parameters = [ param1: 'hello'], make sure param1 matches the web method parameter name exactly), and the function you want called on success (must accept a single parameter that is the returned data). This function may need to change based on your web-service setup.

function makeWsCall(methodNameVar, paramatersVar, successFunc) {
            jQuery.support.cors = true; // force cross-site scripting (as of jQuery 1.5)
            $.ajax({
                url: '<%=postUrlCodeBehind%>' + "/" + methodNameVar, // url + method name
                type: 'GET', // http request type
                data: paramatersVar, // paramaters to be passed to the ws
                ContentType: "application/json; charset=utf-8",
                dataType: 'json', // expected return type
                //traditional: true,
                //            dataType: 'jsonp',
                timeout: 200000, // timeout, may not be needed
                success: function (data) {
                    var returnObject = eval(data);
                    successFunc(returnObject); // call the function passed to the method
                }, //successFunc(data),
                error: function (data) { // on error method
                   // do nothing on error
                }
            });
        };
StMotorSpark
  • 201
  • 1
  • 7
  • I kind of had a feeling I will probably need to take an approach like this, actually. I am just trying to scope out everyone's thoughts on the matter. I'll be trying some various ideas in the meantime. Thanks! – aohm1989 Jun 05 '13 at 14:36
  • Well once you have the Ajax method made it is extremely easy to reuse. The biggest challenge with this approach is getting the web-service initially set up. After you get it initially working, additional methods or web-service changes are easy. I can send you the basic Ajax wrapper method I use if it would be helpful. – StMotorSpark Jun 05 '13 at 14:39
  • It could only be helpful :) – aohm1989 Jun 05 '13 at 14:59
  • I added the wrapper function to the original answer. Hope it helps. – StMotorSpark Jun 05 '13 at 15:10