Skip to main content
Inspiring
August 8, 2013
Answered

jqGrid Server side

  • August 8, 2013
  • 1 reply
  • 5067 views

I use jqGrid for my project using following server side code for ColdFusion in my cfc file.

The jqGrid works only for a few pages.

I can scroll for a couple of page using jqGrid pager.

It seems that the page and records information does not send to jqGrid correctly.

Do I need to particular to pass any row, pages and records information from client to make server response correct pages?

Your help and information is great appreciated,

Regards,

Iccsi,

<cffunction name="ccdClaimsLookup" access="remote" returnformat="json">
  
    <cfargument name ="StartDate" required="no" default="">
    <cfargument name ="EndDate" required="no" default="">
    <cfargument name="page" required="no" default="1">
    <cfargument name="rows" required="no" default="10">
    <cfargument name="sidx" required="no" default="">
    <cfargument name="sord" required="no" default="ASC">
   
    <cfset var Mydata = ArrayNew(1)>

     <cfset start = ((arguments.page-1)*arguments.rows)+1>
     <cfset end = (start-1) + arguments.rows>
     <cfset i = 1>

    <cfstoredproc procedure="MySP">
           
      <cfprocparam value = "#StartDate#" CFSQLTYPE = "cf_sql_date">
      <cfprocparam value = "#EndDate#" CFSQLTYPE = "cf_sql_date">
    
      <cfprocresult name="spname" resultset="1">
  </cfstoredproc>
 
     <cfloop query="spname" startrow="#start#" endrow="#end#">

       <cfset Mydata = [#MyID#,#MyName#,#MyDate#,#MyNote#]>

            <cfset i = i + 1>           
  </cfloop>

     <cfset totalPages = Ceiling(spname.recordcount/arguments.rows)>
     <cfset stcReturn = {total=#totalPages#,page=#Arguments.page#,records=#spname.recordcount#,rows=#Mydata#}>
       

<cfreturn #serializeJSON(stcReturn, True)#>
    
</cffunction>

    This topic has been closed for replies.
    Correct answer Carl Von Stetten

    Thanks for the message and help,

    they are cfc file.

    How can I use it, any user document for this or I just have the file in my components folder and calling from my cfc cffunction?

    Thanksa gain for helping and information,

    regards,

    Iccsi,


    You can instantiate an object for the JSONUtil.cfc anywhere in your code that you want.  I usually instantiate it in my Application.cfc onApplicationStart() method and store it as application.JSONUtil (as a variable in the application scope).  I keep all my utility cfc's in a "cfc" folder off the web root, so to instantiate the CFC in my Application.cfc I have this:

    application.JSONUtil = createObject("component","cfc.JSONUtil");

    Then I can call application.JSONUtil.serializeJSON() or application.JSONUtil.deserializeJSON() wherever I need to in my code.

    HTH,

    -Carl V.

    1 reply

    Carl Von Stetten
    Legend
    August 8, 2013

    @Isccsi,

    I can't comment on the data you are passing to jqGrid, as I haven't used that jQuery plugin myself.  I did notice one thing that could be a problem.  You are using the SerializeJSON() function on your data, but you are also specifying the ReturnFormat on your function as JSON.  Specifying the ReturnFormat causes the value being returned to automatically be serialized to JSON; thus, you are serializing your data twice (once by calling the SerializeJSON function, then ColdFusion does it again automatically when it returns the data).  This may cause JSON to become malformed. 

    Since you are not returning your query directly from your function (you are looping through it and building an array of arrays), you shouldn't need the SerializeJSON call at all.  You should be able to just return your stcReturn variable.

    HTH,

    Carl V.

    iccsiAuthor
    Inspiring
    August 9, 2013

    Thanks a million for the message and help,

    jqGrid does not crash any more, but it skips a few pages.

    Can the function return query direct not need put in array?

    Thanks agin for helping,

    Regards,

    Iccsi,

    p_sim
    Participating Frequently
    August 10, 2013

    jqGrid only outputs the data. Data retrieval is done in the CFC. So, check if you CFC does its job properly.