Where to render Ajax search results in an object oriented approach using Coldfusion?

245 views Asked by At

I'm updating a Coldfusion8/MySql site with a fairly complex search from "spaghetti to object" (= separate view, controller and process - no framework, everything handled by Jquery Mobile).

I need to run the search query through Jquery-AJAX and am now posting the search form to my searchProcess.cfc, which does the database queries.

Question:
I'm not sure where to render the results?

The results will be fairly complex (database with a few million records, rows of 40 fields) and should end up in a single result layout or a multiple result layout file.

I was thinking of constructing the files inside the cfc and handing them back via cfsavecontent, but I'm reading everywhere this is a no-no...

What are the alternatives then?

I could set up a template_single.cfm and template_multi.cfm, pass back pure search results as AJAX response and then fire another AJAX call from the success handler to call the template and then render the output of this 2nd call. This seems awfully complicated, plus I don't see where I can fit my pagination in there without passing around large datasets.

So I'm looking for some advice on how to handle search-results in an object-oriented-way?

Thanks for input!

EDIT:
After a few more hours of googling, I'm currently looking at the following option:
1.) run a single database query to return paginated results - as per here
2.) send data with 0-25 records back to AJAX in JSON
3.) trying to use a template cf/js in a loop (length 1 or length 25) - as per here

This would mean data-transfer only for 1-25 raw records in JSON. If I try to render in the success handler, I'm not having to http-request another template.

Does this approach make sense?

1

There are 1 answers

2
Sharondio On BEST ANSWER

First off, I see nothing wrong with putting display logic in a .cfc that is specifically for display logic. I know it's not strict MVC, but depending on what you're doing, it can work just fine. What I don't like is .cfc's that do any sort of output within the function. I always hand back any data from the function.

/end opinion

For this particular problem, I second EDIT idea of setting up the view to be almost all HTML/jQuery with AJAX calls for paginated recordsets. As far as the single/multiple results, I'd go with separate jQuery functions depending on which one you needed. The nice thing about this is that you could have the multiple recordset display call the single record display to view a single record (while still retaining the full recordset in the Dom).

In both cases, I highly recommend getting a Javascript Dump function (helps so much in visualizing the DOM data.)

PS. If anybody finds any newer/better JS Dump functions that work like cfdump, please, please, please let me know!