Question

I am trying to build a tab based alphabet set by the employees in a database, this way it wont be a set a-z but dynamically built based on the employees in the database. here is the query:

<cffunction name="ALPHA_RL" access="remote" returnformat="JSON" returntype="any"  >
        <cfargument name='DEPTMATRICSID' required='true' />
        <cfset retVal = ArrayNew(1)>
        <cfquery datasource="#request.DSN#" username="#request.User#" password="#request.Password#" name="getAlphaList">
                SELECT DISTINCT ALPHA FROM (
                SELECT SUBSTR(A.LAST_NAME, 1, 1) As ALPHA
                FROM WEBSCHEDULE.APPLICATION_USER A, WEBSCHEDULE.FACULTYHISTORY H, WEBSCHEDULE.FACULTYTABLE T
                WHERE A.EMPLID = H.FACULTYEMPLID
                AND A.EMPLID = T.EMPLID
                AND H.DEPTMATRICSID = #ARGUMENTS.DEPTMATRICSID# )
                WHERE ALPHA IS NOT NULL
                ORDER BY ALPHA
        </cfquery>
        <cfloop query="getAlphaList">
            <cfset temp = {} />
            <cfset temp['ALPHA'] = getAlphaList.ALPHA />
            <cfset ArrayAppend(retval, temp)>
        </cfloop>
        <cfset result = {} />
        <cfset result['items'] = retVal />

        <cfreturn result>
    </cffunction>

That works good and returns the desired data show below:

{"items":[{"ALPHA":"A"},{"ALPHA":"B"},{"ALPHA":"C"},{"ALPHA":"F"},{"ALPHA":"G"},{"ALPHA":"H"},{"ALPHA":"J"},{"ALPHA":"L"},{"ALPHA":"M"},{"ALPHA":"N"},{"ALPHA":"O"},{"ALPHA":"P"},{"ALPHA":"R"},{"ALPHA":"S"}]}

Now where is where I have the issue in my html page I created a function and loop threw the above results to build the html for the tabs:

function alphaTabs(d){
$.ajax({
    url: "CFCs/ManageUserProfiles.cfc",
    dataType: "json",
    data: {
        method: "ALPHA_RL",
        DEPTMATRICSID: d
    },
    success: function(response){
        var x = response.items;
        var str = '';
        if (response.items[0] != undefined) {

            str += '<ul>';
            for (var i = 0; i < x.length; i++) {
                str += '<li><a href="#alphaTabz-' + x[i].ALPHA + '">' + x[i].ALPHA + '</a></li>';
            }
            str += '</ul>';
            for (var j = 0; j < x.length; j++) {
                str += '<div id="alphaTabz-' + x[j].ALPHA + '">';
                str += '<p>' + j + '</p>';
                str += '</div>';
            }

        }
        $('#displayAlphaList').append(str);
    },
    error: function(data){
    }
});
}

Here is how I call the jquery tabs in my document.ready:

$('#displayAlphaList').tabs();
var d = '<cfoutput>#session.ad.AppDeptID#</cfoutput>';
alphaTabs(d)

The html generated is fine but the call to the $('#displayAlphaList').tabs() doesn't recognize the tabs thus it looks like just plain html and the tabs are not created. Thanks in advance for any insight you can help me with.

Was it helpful?

Solution

You are calling the $('#displayAlphaList').tabs() BEFORE you create your tabs.

You need to call $('#displayAlphaList').tabs(); at the end of your 'success' function.

function alphaTabs(d){
$.ajax({
    url: "CFCs/ManageUserProfiles.cfc",
    dataType: "json",
    data: {
        method: "ALPHA_RL",
        DEPTMATRICSID: d
    },
    success: function(response){
        var x = response.items;
        var str = '';
        if (response.items[0] != undefined) {
            str += '<div id="displayAlphaList">'
            str += '<ul>';
            for (var i = 0; i < x.length; i++) {
                str += '<li><a href="#alphaTabz-' + x[i].ALPHA + '">' + x[i].ALPHA + '</a></li>';
            }
            str += '</ul>';
            for (var j = 0; j < x.length; j++) {
                str += '<div id="alphaTabz-' + x[j].ALPHA + '">';
                str += '<p>' + j + '</p>';
                str += '</div>';
            }
            str += '</div>';
        }
        $('#alphaList').html(str);
        $('#displayAlphaList').tabs();
    },
    error: function(data){
    }
});
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top