• View
  • Source
First name Last name
Please wait
{FIRSTNAME} {LASTNAME}


Get records sample 2

First name Last name
Please wait
{FIRSTNAME} {LASTNAME}

Handler

<cffunction name="dspNestedJSONDataSet" access="public" returntype="void" output="false">
    <cfargument name="Event" type="coldbox.system.beans.requestContext">
    <cfset var spry = getPlugin("Spry",true)>
    <cfset spry.setJSONDataSet("dsUserList1_parentDs","?event=spryExample.getUsersJSON","useCache: false")>
    <cfset spry.setNestedJSONDataSet("dsUserList1","dsUserList1_parentDs","data.FIRSTNAME","useCache:false")>
    <cfset spry.setJSONDataSet("dsUserList2_parentDs","null","useCache: false")>
    <!--- Create js function to fill data set dsUserList2 --->
    <cfset spry.setNestedJSONDataSet("dsUserList2","dsUserList2_parentDs","data.LASTNAME")>
        <cfset spry.setJavascript("function getUserList2(){dsUserList2_parentDs.setURL('?event=spryExample.getUsersJSON');dsUserList2_parentDs.loadData();}",true)>
    <cfset spry.setCSSLink("includes/css/list.css","screen")>
    <cfset Event.setView("spryExample/dataSet")>        
</cffunction>

<cffunction name="getUsersJSON" access="public" returntype="void" output="false">
    <cfargument name="Event" type="coldbox.system.beans.requestContext">
    <cfset var JSON = getPlugin("JSON",true)>
    <!--- Get query users --->
    <cfset var users = getUsers()>
    <!--- Encode query to JSON --->
    <cfset Event.setValue("data",JSON.encode(data:users,queryKeyCase:"upper"))>

    <!--- Call AjaxProxy to output data --->
    <cfset Event.setView("ajaxProxy",true)>        
</cffunction>

View

<div spry:region="dsUserList1" id="dsUserList1Region"> 
    <table class="list">
        <thead>
            <tr>
                <th width="150">First name</th>
                <th>Last name</th>
            </tr>
        </thead>
        <tbody spry:state="loading">
            <tr>
                <td colspan="2">Please wait</td>
            </tr>
        </tbody>
        <tbody spry:repeat="dsUserList1" spry:state="ready">
            <tr class="{ds_EvenOddRow}" spry:hover="hover" spry:select="selected"
                onclick="alert('RowID {ds_RowID} clicked')">

                <td>{FIRSTNAME}</td>
                <td>{LASTNAME}</td>
            </tr>
        </tbody>
    </table>
</div>
<br /><br />
<a href="javascript:getUserList2()">Get records sample 2</a>
<br />
<br />
<div spry:region="dsUserList2" id="dsUserList2Region">
    <table class="list">
        <thead>
            <tr>
                <th width="150">First name</th>
                <th>Last name</th>
            </tr>
        </thead>
        <tbody spry:state="loading">
            <tr>
                <td colspan="2">Please wait</td>
            </tr>
        </tbody>
        <tbody spry:repeat="dsUserList2" spry:state="ready">
            <tr class="{ds_EvenOddRow}" spry:hover="hover" spry:select="selected" onclick="alert( '{FIRSTNAME} {LASTNAME}')">
                <td>{FIRSTNAME}</td>
                <td>{LASTNAME}</td>
            </tr>
        </tbody>
    </table>
</div>