Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Select box is empty on the editform or addform
Tags: jqgrid
02/10/2012
23:18
Avatar
sokol
Member
Members
Forum Posts: 5
Member Since:
02/10/2012
sp_UserOfflineSmall Offline

Hi

Could anyone check what is wrong with my code? When I bring edit or add form the select box that should be populated displays Error. I am trying to display list of companies in drop down list on edit and addform.

This is data from cfc action proc shown in firebug:

{"ROWS":[["5_1","ABC Company"],["10_2","Main Division"],["24_3","Mines - Hourly Program"],["22_3","Mines - Salaried Program"],["6_1","First Capital"]]}

jqGid:

{name:'description',index:'description', width:150, sorttype:"text",editable:true,searchoptions:{sopt:['eq','lt','le','gt','ge']},edittype:"select",
                                editoptions:{dataUrl:myURL + '?method=GetProvJ',
                                                
                                                buildSelect:                                                     
                                                    function(data) {  
                                                        var response = typeof(data) === "string" ? jQuery.parseJSON(data.responseText): data;                                                                                                             
                                                         var s = '<select>';  
                                                         if (response && response.length) {  
                                                            for (var i = 0, l=response.length; i<l; i++) {  
                                                                 s += '<option value="'+response[i]+'">'+response[i]+'</option>';  
                                                             }  
                                                         }
                                                        else
                                                            s += '<option value="0″>Error</option>';
                                                            
                                                         return s + "</select>";  
                                                    }
                                                },
                                editrules:{required:true},
                                formoptions:{elmprefix:"(*)"}},

CFC:

<cffunction name="GetProvJ" access="remote" returnformat="json" output="false">
        
        <cfquery name="Lst" datasource="#REQUEST.dsn#" username="#REQUEST.dbusername#" password="#REQUEST.dbpassword#">
            SELECT TOP 2 name, Convert(varchar(10),s.my_id) + '_' + Convert(varchar(10),s.account_id) AS id
                FROM tblCompanies s
                WHERE account_id = 1                
            ORDER BY name
        </cfquery>
        
        <cfset var arrTrans = arrayNew(1)>
        <cfset var i = 1>
        <cfloop query="Lst">
            <cfset VARIABLES.arrTrans[i] = [#id#,#name#]>
            <cfset i = i + 1>            
        </cfloop>
        
        <cfset strReturn = {rows=arrTrans}>
        
        <cfreturn strReturn>
    </cffunction>

03/10/2012
17:13
Avatar
sokol
Member
Members
Forum Posts: 5
Member Since:
02/10/2012
sp_UserOfflineSmall Offline

I made some changes and now data is displayed in the drop down but it is parsed vertically one letter at a time per line and displayed not only name and id but all the characters including ", {, R, O, W, S… so, either my javascript has some problem or to apply some json formatting in the cfc?

Data from cfc looks like this:

{"ROWS":[{"id":"5_1","name":"ABC Company"},{"id":"10_2","name":"ABC Inc, Main Division"},{"id":"24_3","name":"Mines - Hourly Program"},{"id":"22_3","name":"Mines - Salaried Program"},{"id":"6_1","name":"Capital Realty"}]}

I changed javascirpt since I already receive JSON to this:

Old:

function(data) {  
         var response = typeof(data) === "string" ? jQuery.parseJSON(data.responseText): data;

          …………

New:

function(response){….. 

I changed cfc to this:

<cffunction name="GetProvJ" access="remote" returnformat="json" returntype="struct" output="false">
        
        <cfquery name="Lst" datasource="#REQUEST.dsn#" username="#REQUEST.dbusername#" password="#REQUEST.dbpassword#">
            SELECT name, Convert(varchar(10),s.id) + '_' + Convert(varchar(10),s.account_id) AS id
                FROM tblCompanies s
                WHERE s.account_id = 1
            ORDER BY name
        </cfquery>
        
        <cfset var arrTransactions = arrayNew(1)>
        
        
        <cfloop query="Lst">
                <cfset returnStruct = StructNew() />
                <cfset returnStruct["name"] = name />
                <cfset returnStruct["id"] = id />
                <cfset ArrayAppend(VARIABLES.arrTransactions,returnStruct) />
      </cfloop>
                
      <cfset strReturn = {rows=arrTransactions}>
        
      <cfreturn strReturn>

</cffunction>

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
45 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information