Posts

Showing posts from January, 2015

Select2 Grouped Static Data With AJAX Search Fallback

Image
GIST =>  Select2 Grouped Static Data With AJAX Fallback

I have a database table named Locations which contains hierarchical data which again grouped by a title. To take the confusion off, here's the sample JSON returned from my API.

{ "results":[ { "text":"Country", "children":[ { "id":11082, "text":"SRI LANKA (LK)" }, { "id":10627, "text":"MAURITIUS (MU)" } ] }, { "text":"Airport", "children":[ { "id":17269, "text":"Katunayake Airport" } ] }, { "text":"City", "children":[ { "id":25845, "text":"Kandy" }, { "id":25829, "text":"Galle" } ] } …

MSSQL - Get Comma Separated String from multiple rows

Image
I'm a big fan of Select2 library and there are instances where I have to use the multiple selections. like the ones below.
I store them values in a table structure which looks like the following.
This table maps the One-to-Many relationship between my service profiles and facilities. (One profile has many facilities). Using Select2, I can select many facilities at once.

Select2 serializes the Facility IDs as a comma separated string and I have to split it into individual facility IDs to store in the database. Storing the CSV string is a bad idea. How the hell are you going to query them?
-- delcare a new test table DECLARE @Table1 TABLE ( ID INT, Value INT); -- insert dummy values INSERT INTO @Table1 VALUES (1, 100), (1, 200), (1, 300), (1, 400);
Query To convert the values into a CSV string
SELECT ID, STUFF((SELECT ', ' + CAST (Value AS VARCHAR (10)) AS [text()] FROM @Table1 …

Simple Wizard using Knockout.js

My scenario isn't all that simple tho. Imagine I have a customer type on my wizard and depending on this type, I have to choose the next step of the wizard. How would you do it with less code in a more reusable, easy to modify way?

To give you an idea, I have setup a jsfiddle for you.

Let me see if I can embed it here...



Note: I have used the following libs.
underscore.js  - http://jashkenas.github.io/underscore/knockout - http://knockoutjs.com/twitter-bootstrap  - http://getbootstrap.com/ The code should be easier to follow. There is a "stepModels" array containing all the steps and its related templates. it also contains template type option which indicates the path it should take if the customer type is a business.

commented almost every step of the code so it should be easier to understand.