Thursday, June 7, 2012

Adding a trigger button for Datepicker


jQuery UI Adding a trigger button for Datepicker tutorial. By default, user can open datepicker when <input> element receives focus. we can change this very easily. We can make datepicker opens when a button is clicked instead. The most basic type of <button> can be enabled with just the showOn option
1$(function(){
2    var pickerOpts = {
3        showOn: "button"
4    }; 
5    $("#date").datepicker(pickerOpts);
6});
Complete Example Code:
01<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
02<html lang="en">
03<head>
04<link rel="stylesheet" type="text/css" href="development-bundle/themes/ui-lightness/jquery.ui.all.css">
05<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
06<title>jQuery UI Datepicker Example 1</title>
07<script type="text/javascript" src="development-bundle/jquery-1.4.2.js"></script>
08<script type="text/javascript" src="development-bundle/ui/jquery.ui.core.js"></script>
09<script type="text/javascript" src="development-bundle/ui/jquery.ui.datepicker.js"></script>
10<script type="text/javascript">
11    $(function(){
12        var pickerOpts = {
13            showOn: "button"
14        }; 
15        $("#date").datepicker(pickerOpts);
16    });
17</script>
18</head>
19<body>
20<label>Enter a date: </label><input id="date">
21</body>
22</html>
jQuery UI Adding a Trigger Button for Datepicker Tutorial
We can change the default text that show on the button. just providing a new string as the value of the buttonText option:
1$(function(){
2    var pickerOpts = {
3        showOn: "button",
4        buttonText: "Show Datepicker"
5    }; 
6    $("#date").datepicker(pickerOpts);
7});
jQuery UI Change text for trigger button for datepicker tutorial
1$(function(){
2    var pickerOpts = {
3        showOn: "button",
4        buttonImage: "img/datepicker/date.png",
5        buttonText: "Show Datepicker"
6    }; 
7    $("#date").datepicker(pickerOpts);
8});
jQuery UI Adding image for trigger button of datepicker tutorial

Sunday, May 27, 2012

Paging through Records using a Stored Procedure



Working with my database administrator, I developed a stored procedure for use with SQL Server that puts the burden on the SQL Server to only return the required number of records to the web server instead of the entire database table. This GREATLY reduces the load factor on the web server when making database requests. The explanation of the code follows the stored procedure. In this example, we are retrieving item pricing information from a table and returning N records.


CREATE PROCEDURE CREATE PROCEDURE usp_RoomsPagedItems 
 (
  @Page int
    )
AS
-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON
DECLARE @RecsPerPage int
-- Find out where we will start our records from
DECLARE @RecCount int
SET @RecsPerPage = 20
SELECT @RecCount = @RecsPerPage * @Page + 1


--Create a temporary table
CREATE TABLE #TempItems
(
 ID int IDENTITY,
 ROOMNAME varchar(50),
 ROOMID int,
 ROOMTYPEID int
)
-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (ROOMNAME, ROOMID,ROOMTYPEID)
SELECT  'ROOM ' + ROOM.ROOMNO AS ROOMNAME,
   ROOM.ID AS ROOMID,
   ROOMTYPE.ID AS ROOMTYPEID
  FROM DBO.ROOMTYPE INNER JOIN DBO.ROOM ON ROOM.ROOMTYPEID = ROOMTYPE.ID
--ORDER BY CAST(ROOM.ROOMNO AS NUMERIC)
ORDER BY ROOM.ROOMNO

-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
       MoreRecords = 
 (
  SELECT COUNT(*) 
  FROM #TempItems TI
  WHERE TI.ID > @LastRec
 ) 
FROM #TempItems
WHERE ID > @FirstRec AND ID < @LastRec


-- Turn NOCOUNT back OFF
SET NOCOUNT OFF