Free DNN Module: DNNStuff SQLView - Sort EVENTS module events by City / County / State

Location: BlogsAll BlogsDNN Development    
Posted by: mamlin 11/10/2008 3:50 PM

If you need an upgrade from Efficion Consulting's free (but aging) "Advanced DataGrid" (ADG) module, DNNStuff's free SQL module may be the answer.  "SQLView" does what ADG does and does a few things better.  The drawback?  SQLView is not open-sourced like ADG.  If you think "FREE is FREE" and you don't care about having access to the source code, read on...

DNNStuff SQLView
Ok, so what does SQLView do for us that the Advanced DataGrid can't?  There are a number of very notable items, actually:

  • Specify a different data provider
    You can pull data from any SQL source, not just the default DNN database.
  • Support for Querystring values
    You can include tokens in your SQL based on querystring values.  Very useful.
  • Robust column sorting
    The Advanced DataGrid has a fragile implementation for column sorting, often resulting in SQL errors when attempting to use the "click a column to sort" feature.  SQLView is more intelligent:  it separates your query's "SORT BY" clause (if any) from the main query resulting in a robust "click-to-sort" feature (I haven't broken it, yet).
  • XSL Transformations
    SQLView provides an option to have the returned data transformed by your own XSL code, either a local XSL file or a remote file accessed as a URL.
  • Well-exposed CSS styling
    SQLView provides the ability to direclty link CSS classes to the returned table (grid), table header, row, alternating row and pager.

Sold, yet?  Remember -- SQLView is a FREE module.  You can get the module here:  http://www.dnnstuff.com



SQLView example:  Sortable List of Events
Let's jump right into a real-world example.  A blog reader asked me about generating a sortable list of events from the DNN Events module.  This user wants to sort not just by event name and date, but also by location:  state, county and city.  Let's use SQLView to do a little Events list magic:

(Assuming you already have SQLView installed and have added it to a test page.)

(1) First, go into the SQLView module's OPTIONS (not SETTINGS, but OPTIONS).
As you'd expect from a SQL module, the main entry field you see is the "Query" field.  Copy-and-paste the following query into the "Query" field:

SELECT     
  EventName AS [Event Name],  
  EventTimeBegin AS [Start Time],

  CASE WHEN ev.Location > 1 THEN

    substring
     (evl.LocationName, 0, charindex(',',evl.LocationName))
    ELSE 'n/a'
    END as [City],

  CASE WHEN ev.Location > 1 THEN
    substring
     (evl.LocationName, charindex(',',evl.LocationName)+1,

      len(evl.LocationName) - 3 -
      len(substring(evl.LocationName, 0,
          charindex(',',evl.LocationName))) -
      len(reverse(substring(reverse(evl.LocationName), 0,
          charindex(',',reverse(evl.LocationName)))))+1)
    ELSE 'n/a'
 END as [County],

  CASE WHEN ev.Location > 1 THEN
    reverse(substring(reverse(evl.LocationName), 0,
            charindex(',',reverse(evl.LocationName))))
  ELSE 'n/a'
 END as [State]

FROM Events AS ev left join
  eventslocation evl on evl.location = ev.locatio
n


The only other setting you need to worry about is the "Allow Sorting" option -- make sure this is checked.  That's it.


The SQL Query

Remember that this is just a quick-and-dirty example so you can try out the module with minimal effort.  In practice you would add a custom function to your database to provide a robust string tokenizer to be called upon by your query to extract city/county/state info from the "location" string value.  For this example, though, we're going to do it all in a single, messy query.  Because of this, the code to display CITY, COUNTY and STATE will look a bit strange since we're doing simple string parsing on the fly rather than tokenizing as we'd prefer to do.

Here's what the query does:  The query returns the event name, start time and the (if specified) city, county and state as individual columns.  The EVENTS module does not provide specific fields for CITY, COUNTY or STATE.  Instead, you are allowed to provide a "location" string.  For our simple example here, we are using the "location" to define CITY, COUNTY and STATE by entering the location information in the form of "(city), (county), (state)".  Note that for our example to work it is vitial that the location (if specified) contain TWO commas as delimiters.  If an event does not specify a location the city, county and state fields will show "n/a".
 

What's Missing
This is as basic as it gets -- merely a proof-of-concept to provide an event list and introduce the free SQLView module.  This example does not take into account the possiblity of multiple event calendars, event dates that have passed, events with incomplete (or mal-formed) location information, etc.  Hopefully it's enough, though, to give you a start on making your own (robust) solution to whatever problem you're tackling.  Cheers!

 

 

 

 

Permalink |  Trackback

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
You are here:  
 
>> Back to the top of the blog list...

 
        account   advanced   blog   click   cloud   code   content   create   data   different   events   example   feature   file   files   free   function   good   google   just   line   list   module   modules   need   option   page   pages   query   results   role   roles   script   search   select   settings   simple   site   skin   solution   step   tags   terms   time   user   users   value   version   want  
Minimize Google AJAX Search
 
Search ES:  
This is an example of a Google AJAX Search with asynchronous search execution for two searches.  See our blog series, 'Add Google AJAX Search to your DNN skin' for info and sample code.
 
     
Minimize Get the T-Shirt
 
Shirts by Eguana Solutions
(Be cool like us!)
 
     
Minimize Most-Commented Blogs
 
 
     

Minimize Looking for more info?
 

There are tons of helpful
posts from Eguana Solutions 
on the DotNetNuke.com forums.
  
 
Click HERE to see our posts.

 
     
Minimize Modules for Sale
 

Looking for Eguana's modules? 
We're still working on them!
  

Until ours are ready to dazzle and
amaze, you'll have to make do with
the thousands of modules already
available on SnowCovered.

 
     
Minimize Favorite Modules
 

There are many great DNN modules.
A few we highly recommend are:
 
Dynamic Registration
Total control over the user signup process.  Create custom forms, execute your own SQL, use the integrated payment processing features to assign user roles, validate USERNAMEs via AJAX and much more.  Very cool.
 
URL Master
Change to friendly URLs that really ARE friendly.  Add keywords into your page URLs for better SEO.  Create 301 redirects for individual pages.  Force visitors (and search bots) to a single domain (i.e., make everyone use the "www" version of your site's URL or vice versa).  One of the single best upgrades for any DNN site.
 
Document Exchange 5 (DMX5)
Drag-and-drop from Windows Explorer directly into the DMX file manager!  File versioning, file and folder moderation, extend user permissions down to the file level (for user groups and even for individual users).  Infinite file and file info presentation options via custom display templates.  Store files locally or remotely via UNC (i.e., can securely store files somewhere besides your web server).  Much more.
 
XMOD by DNNDev
Rock-solid form module for data collection.  From simple feedback / email forms to complex, multi-part tabbed forms.  XMOD is different from other form modules because XMOD does not create a new database table for every new form definition -- an important feature if you plan to create dozens or hundreds of forms over the life of your DNN instance!  Excellent support from the developer and an active community around this module.
 
If you desire your form module to create a new DB table for each new form definition, a great alternative to XMOD is the Dynamic Forms module from DataSprings.  Dynamic Forms offers direct DB access beyond that found in XMOD as well as an easy drag-and-drop form builder option to help you get up and running very quickly.

 
     

Login