Paging in jquery with sp or without sp
-- =============================================
-- Author:
-- Create date:
-- Description:
-- USP_Location_GetByPhysicalProperty @KeyWord='',@Sort='',@PageNumber=1,@PageSize=5,@LanguageId=1,@CommandCenterId='00000000-0000-0000-0000-000000000000',@CompanyId='00000000-0000-0000-0000-000000000000'
CREATE PROCEDURE [dbo].[USP_Location_GetByPhysicalProperty]
@KeyWord varchar(100),
@Sort varchar(50),
@PageNumber int,
@PageSize int,
@LanguageId varchar(10),
@CommandCenterId uniqueidentifier,
@CompanyId uniqueidentifier
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SqlColumnQuery NVARCHAR(max) =''
DECLARE @SqlWhereQuery NVARCHAR(max) =''
DECLARE @SqlJoinQuery NVARCHAR(max) =''
DECLARE @SqlQueryPaging NVARCHAR(max) =''
DECLARE @find nvarchar(5)
DECLARE @replace nvarchar(5)
--to resove apostrophe appended error
SET @find =''+char(39)+''
SET @replace = ''+char(39)+char(39)+''
SET @Keyword = replace(@Keyword,@find,@replace)
IF(@PageNumber IS NULL)
BEGIN
SET @PageNumber = 1
END
IF(@PageSize IS NULL)
BEGIN
SET @PageSize = 10
END
IF (@Sort = '')
BEGIN
SET @Sort = 'LocationName'
END
SET @SqlColumnQuery ='tblLocation.Name AS LocationName
, tblLocationType_Lang.Name AS LocationTypeName
,tblLocation.LocationId
,((SELECT STUFF((SELECT ''-'' + LS.Name
FROM tblLocationStorage LS
INNER JOIN tblLocationSegment TLS ON TLS.LocationSegmentId = LS.SegmentId
WHERE LS.GroupId = tblinventory.StorageID AND LS.Name != '''' ORDER BY TLS.DisplayOrder
FOR XML PATH ('''')), 1, 1, ''''))) AS StorageName
,tblinventory.StorageID '
SET @SqlJoinQuery =' FROM tblLocationType_Lang
INNER JOIN tblLocationType
ON tblLocationType_Lang.LocationTypeId = tblLocationType.Id and tblLocationType_Lang.LanguageId=1 AND tblLocationType.IsActive = 1
INNER JOIN tblLocationTypeMapping
ON tblLocationType.Id = tblLocationTypeMapping.LocationTypeId AND tblLocationTypeMapping.IsPrimary = 1
INNER JOIN tblLocation
ON tbllocation.LocationId=tblLocationTypeMapping.LocationId
INNER JOIN tblinventory
ON tbllocation.LocationId=tblinventory.StorageLocationID
INNER JOIN tblitem
ON tblinventory.ItemID=tblitem.ID
INNER JOIN tblitemtemplate
ON tblitem.ItemTemplateID=tblitemtemplate.Id
INNER JOIN tblResourceType
ON tblitemtemplate.ResourceTypeId=tblResourceType.ID
WHERE tbllocation.CompanyId='''+Convert(nvarchar(50),@CompanyId)+'''
AND tbllocation.CommandCenterId='''+Convert(nvarchar(50),@CommandCenterId)+'''
AND tblResourceType.IsPhysicalProperty=1'
IF (@KeyWord <> '')
BEGIN
SET @SqlWhereQuery = 'AND (tblLocation.Name LIKE ''%'+ @KeyWord +'%'')'
END
Set @SqlQueryPaging=')T) T1 WHERE ROWNUM BETWEEN ('+Convert(nvarchar(50),@PageNumber)
+' * '+Convert(nvarchar(50),@PageSize) +'+ 1 - '+Convert(nvarchar(50),@PageSize)+')
AND ('+Convert(nvarchar(50),@PageSize)+' * '+Convert(nvarchar(50),@PageNumber)+') '
EXEC ('DECLARE @Count INT
SELECT @Count = COUNT(*) FROM (
SELECT DISTINCT '+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + '
) TTY SELECT * FROM ( SELECT *, ROW_NUMBER() OVER(ORDER BY '+ @Sort+') as RowNum
FROM ( SELECT DISTINCT @Count AS Total,'+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + @SqlQueryPaging)
Print ('DECLARE @Count INT
SELECT @Count = COUNT(*) FROM (
SELECT DISTINCT '+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + '
) TTY SELECT * FROM ( SELECT *, ROW_NUMBER() OVER(ORDER BY '+ @Sort+') as RowNum
FROM ( SELECT DISTINCT @Count AS Total,'+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + @SqlQueryPaging)
END
------------------------------------------------------------------------------------------------------------------------------------------------
Paging ddl and div
Page Size:
---------------------------------------------------------------------------------------------------------------------------------------------
Paging function jquery
// Get all location by property
GetLocationByProperty: function () {
var data = { keyword: PropertyLocation.KeyWordLocation, sort: PropertyLocation.LocationSortExp, pageNumber: PropertyLocation.PageNumberLocation, pageSize: PropertyLocation.PageSizeLocation }
var pageSize = $('#ddlLocationPopupPaging').val();
$.ajax({
type: "POST",
url: $("#hdnSitePath").val() + 'WebServices/PropertyVerification.asmx/GetLocationByProperty',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (result) {
if (result.d == null || result.d == 'null') {
window.location = $("#hdnSitePath").val() + "Login/Login.aspx";
}
else {
$("#tblLocationProperty tbody").html("");
var str = "";
for (var i = 0; i < result.d.length; i++) {
str += '';
str += '';
str += ' ' + "Select" + ' ';
str += '' + result.d[i].LocationName + ' ';
str += '' + result.d[i].Storage + ' ';
str += '' + result.d[i].LocationTypeName + ' ';
str += "
";
}
$("#tblLocationProperty tbody").html(str);
if (result.d.length > 0) {
PropertyLocation.TotalLocationRec = result.d[0].Total;
}
else {
PropertyLocation.TotalLocationRec = 0;
}
PropertyLocation.PageSizeLocation = pageSize;
PropertyLocation.NumberOfPagesLocation = Math.ceil(PropertyLocation.TotalLocationRec / PropertyLocation.PageSizeLocation);
}
},
error: function (xhr) {
commonNotification.ErrorMessage(commonNotification.Error + xhr.responseText);
}
});
},
// Paging of locations by Property
PagingGetLocation: function () {
PropertyLocation.GetLocationByProperty();
if (PropertyLocation.NumberOfPagesLocation > 1) {
$('#divLocationPopupPaging').show();
$('#divForPageSize').show();
var displayPage = 8;
if (PropertyLocation.NumberOfPagesLocation < displayPage) {
displayPage = PropertyLocation.NumberOfPagesLocation;
}
$("#divLocationPopupPaging").paginate({
count: PropertyLocation.NumberOfPagesLocation,
start: PropertyLocation.PageNumberLocation,
display: displayPage,
border: true,
border_color: '#fff',
text_color: '#fff',
background_color: '#555',
border_hover_color: '#ccc',
text_hover_color: '#000',
background_hover_color: '#fff',
images: false,
mouse: 'press',
onChange: function (page) {
PropertyLocation.PageNumberLocation = page;
PropertyLocation.GetLocationByProperty(); //change
}
});
}
else if (PropertyLocation.NumberOfPagesLocation == 1) {
$('#divLocationPopupPaging').hide();
$('#divForPageSize').show();
}
else {
$('#divLocationPopupPaging').hide();
$('#divForPageSize').hide();
}
},
----------------------------------------------------------------------------------------------------------------------------------------------
DATA Access function
public List GetAllMessages(string pageNo, string pageSize, string groupId, string sort, int dateFrom, string Keyword, string CompanyID, string CommandCenterID, string UserId)
{
try
{
Int32 PageNumber = Convert.ToInt32(pageNo);
Int32 Pagesize = Convert.ToInt32(pageSize);
SqlConnection sqlConnection = Common.Functions.getConnection();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConnection;
cmd.CommandText = "usp_tblMessage_Summary";
cmd.Parameters.AddWithValue("@Keyword", Keyword);
cmd.Parameters.AddWithValue("@GroupID", groupId);
cmd.Parameters.AddWithValue("@CompanyID", CompanyID);
cmd.Parameters.AddWithValue("@CommandCenterID", CommandCenterID);
cmd.Parameters.AddWithValue("@DateFrom", dateFrom);
cmd.Parameters.AddWithValue("@Sort", sort);
cmd.Parameters.AddWithValue("@UserID", UserId);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill((PageNumber * Pagesize - Pagesize), Pagesize, dt);
if (dt.Rows.Count == 0 && PageNumber > 1)
{
PageNumber--;
da.Fill((PageNumber * Pagesize - Pagesize), Pagesize, dt);
}
-------------------------------------------------------------------------------------------------------------------------------------------------
Jquery.Paginate.js
(function ($) {
$.fn.paginate = function (options) {
var opts = $.extend({}, $.fn.paginate.defaults, options);
return this.each(function () {
$this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
var selectedpage = o.start;
$.fn.draw(o, $this, selectedpage);
});
};
var outsidewidth_tmp = 0;
var insidewidth = 0;
var bName = navigator.appName;
var bVer = navigator.appVersion;
if (bVer.indexOf('MSIE 7.0') > 0)
var ver = "ie7";
$.fn.paginate.defaults = {
count: 5,
start: 12,
display: 5,
border: true,
border_color: '#fff',
text_color: '#8cc59d',
background_color: 'black',
border_hover_color: '#fff',
text_hover_color: '#fff',
background_hover_color: '#fff',
rotate: true,
images: true,
mouse: 'slide',
onChange: function () { return false; }
};
$.fn.draw = function (o, obj, selectedpage) {
$this.empty();
if (o.images) {
var spreviousclass = 'jPag-sprevious-img';
var previousclass = 'jPag-previous-img';
var snextclass = 'jPag-snext-img';
var nextclass = 'jPag-next-img';
}
else {
var spreviousclass = 'jPag-sprevious';
var previousclass = 'jPag-previous';
var snextclass = 'jPag-snext';
var nextclass = 'jPag-next';
}
var _first = $(document.createElement('a')).addClass('jPag-first').html('First');
//$(document.createElement('a')).addClass('jPag-first').html('First');
// $('.jPag-first').attr("id", "fgddd");
// $('#fgddd').html('last_french');
if (o.rotate) {
if (o.images) var _rotleft = $(document.createElement('span')).addClass(spreviousclass);
else var _rotleft = $(document.createElement('span')).addClass(spreviousclass).html('«');
}
var _divwrapleft = $(document.createElement('div')).addClass('jPag-control-back');
_divwrapleft.append(_first).append(_rotleft);
var _ulwrapdiv = $(document.createElement('div')).css('overflow', 'hidden');
var _ul = $(document.createElement('ul')).addClass('jPag-pages')
var c = (o.display - 1) / 2;
var first = selectedpage - c;
var selobj;
for (var i = 0; i < o.count; i++) {
var val = i + 1;
if (val == selectedpage) {
var _obj = $(document.createElement('li')).html('' + val + '');
selobj = _obj;
_ul.append(_obj);
}
else {
var _obj = $(document.createElement('li')).html('' + val + '');
_ul.append(_obj);
}
}
_ulwrapdiv.append(_ul);
if (o.rotate) {
if (o.images) var _rotright = $(document.createElement('span')).addClass(snextclass);
else var _rotright = $(document.createElement('span')).addClass(snextclass).html('»');
}
var _last = $(document.createElement('a')).addClass('jPag-last').html('Last');
var _divwrapright = $(document.createElement('div')).addClass('jPag-control-front');
_divwrapright.append(_rotright).append(_last);
//append all:
$this.addClass('jPaginate').append(_divwrapleft).append(_ulwrapdiv).append(_divwrapright);
if (!o.border) {
if (o.background_color == 'none') var a_css = { 'color': o.text_color };
else var a_css = { 'color': o.text_color, 'background-color': o.background_color };
if (o.background_hover_color == 'none') var hover_css = { 'color': o.text_hover_color };
else var hover_css = { 'color': o.text_hover_color, 'background-color': o.background_hover_color };
}
else {
if (o.background_color == 'none') var a_css = { 'color': o.text_color, 'border': '1px solid ' + o.border_color };
else var a_css = { 'color': o.text_color, 'background-color': o.background_color, 'border': '1px solid ' + o.border_color };
if (o.background_hover_color == 'none') var hover_css = { 'color': o.text_hover_color, 'border': '1px solid ' + o.border_hover_color };
else var hover_css = { 'color': o.text_hover_color, 'background-color': o.background_hover_color, 'border': '1px solid ' + o.border_hover_color };
}
$.fn.applystyle(o, $this, a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright);
//calculate width of the ones displayed:
var outsidewidth = outsidewidth_tmp - _first.parent().width() - 3;
// alert(outsidewidth_tmp);
if (ver == 'ie7') {
_ulwrapdiv.css('width', outsidewidth + 72 + 'px');
_divwrapright.css('left', outsidewidth_tmp + 2 + 164 + 'px');
}
else {
_ulwrapdiv.css('width', outsidewidth + 'px');
_divwrapright.css('left', outsidewidth_tmp + 2 + 'px');
}
if (o.rotate) {
_rotright.hover(
function () {
thumbs_scroll_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() + 1;
_ulwrapdiv.scrollLeft(left);
},
20
);
},
function () {
clearInterval(thumbs_scroll_interval);
}
);
_rotleft.hover(
function () {
thumbs_scroll_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() - 1;
_ulwrapdiv.scrollLeft(left);
},
20
);
},
function () {
clearInterval(thumbs_scroll_interval);
}
);
if (o.mouse == 'press') {
_rotright.mousedown(
function () {
thumbs_mouse_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() + 5;
_ulwrapdiv.scrollLeft(left);
},
20
);
}
).mouseup(
function () {
clearInterval(thumbs_mouse_interval);
}
);
_rotleft.mousedown(
function () {
thumbs_mouse_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() - 5;
_ulwrapdiv.scrollLeft(left);
},
20
);
}
).mouseup(
function () {
clearInterval(thumbs_mouse_interval);
}
);
}
else {
_rotleft.click(function (e) {
var width = outsidewidth - 10;
var left = _ulwrapdiv.scrollLeft() - width;
_ulwrapdiv.animate({ scrollLeft: left + 'px' });
});
_rotright.click(function (e) {
var width = outsidewidth - 10;
var left = _ulwrapdiv.scrollLeft() + width;
_ulwrapdiv.animate({ scrollLeft: left + 'px' });
});
}
}
//first and last:
_first.click(function (e) {
_ulwrapdiv.animate({ scrollLeft: '0px' });
_ulwrapdiv.find('li').eq(0).click();
});
_last.click(function (e) {
_ulwrapdiv.animate({ scrollLeft: insidewidth + 'px' });
_ulwrapdiv.find('li').eq(o.count - 1).click();
});
//click a page
_ulwrapdiv.find('li').click(function (e) {
selobj.html('' + selobj.find('.jPag-current').html() + '');
var currval = $(this).find('a').html();
$(this).html('' + currval + '');
selobj = $(this);
$.fn.applystyle(o, $(this).parent().parent().parent(), a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright);
var left = (this.offsetLeft) / 2;
var left2 = _ulwrapdiv.scrollLeft() + left;
var tmp = left - (outsidewidth / 2);
if (ver == 'ie7')
_ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 52 + 'px' });
else
_ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 'px' });
o.onChange(currval);
});
var last = _ulwrapdiv.find('li').eq(o.start - 1);
last.attr('id', 'tmp');
var left = document.getElementById('tmp').offsetLeft / 2;
last.removeAttr('id');
var tmp = left - (outsidewidth / 2);
if (ver == 'ie7') _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 52 + 'px' });
else _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 'px' });
}
$.fn.applystyle = function (o, obj, a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright) {
obj.find('a').css(a_css);
obj.find('span.jPag-current').css(hover_css);
obj.find('a').hover(
function () {
$(this).css(hover_css);
},
function () {
$(this).css(a_css);
}
);
obj.css('padding-left', _first.parent().width() + 5 + 'px');
insidewidth = 0;
obj.find('li').each(function (i, n) {
// alert(this.offsetLeft);
// alert(n);
// alert(i);
// alert(o.display);
// alert(this.offsetLeft + this.offsetWidth);
if (i == (o.display - 1)) {
outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
// alert(outsidewidth_tmp);
}
// else if (i == 1) {
// outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
// }
// else {
// outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
// }
insidewidth += this.offsetWidth;
})
_ul.css('width', insidewidth + 15 + 'px');
}
})(jQuery);
--------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------
Pstyle.css
.jPaginate{
height:34px;
position:relative;
color:#a5a5a5;
font-size:small;
width:100%;
}
.jPaginate a{
line-height:15px;
height:18px;
cursor:pointer;
padding:2px 5px;
margin:2px;
float:left;
}
.jPag-control-back{
position:absolute;
left:0px;
}
.jPag-control-front{
position:absolute;
top:0px;
}
.jPaginate span{
cursor:pointer;
}
ul.jPag-pages{
float:left;
list-style-type:none;
margin:0px 0px 0px 0px;
padding:0px;
}
ul.jPag-pages li{
display:inline;
float:left;
padding:0px;
margin:0px;
}
ul.jPag-pages li a{
float:left;
padding:2px 5px;
background:#fff !important;
color:#656565 !important;
text-decoration:none;
line-height:17px !important;
border:1px solid #cccccc !important;
}
.jPag-last{background:#fff !important;
color:#656565 !important;
text-decoration:none !important;
line-height:17px !important;
border:1px solid #cccccc !important;}
.jPag-last:hover{ background:#e5e5e5 !important}
.jPag-first{background:#fff !important;
color:#656565 !important;
text-decoration:none !important;
line-height:17px !important;
border:1px solid #cccccc !important;}
.jPag-first:hover{ background:#e5e5e5 !important}
span.jPag-current{
cursor:default;
font-weight:normal;
line-height:17px !important;
height:18px;
background:#e5e5e5 !important;
padding:2px 5px;
margin:2px;
float:left;
}
ul.jPag-pages li span.jPag-previous,
ul.jPag-pages li span.jPag-next,
span.jPag-sprevious,
span.jPag-snext,
ul.jPag-pages li span.jPag-previous-img,
ul.jPag-pages li span.jPag-next-img,
span.jPag-sprevious-img,
span.jPag-snext-img{
height:22px;
margin:2px;
float:left;
line-height:18px;
}
ul.jPag-pages li span.jPag-previous,
ul.jPag-pages li span.jPag-previous-img{
margin:2px 0px 2px 2px;
font-size:12px;
font-weight:bold;
width:10px;
}
ul.jPag-pages li span.jPag-next,
ul.jPag-pages li span.jPag-next-img{
margin:2px 2px 2px 0px;
font-size:12px;
font-weight:bold;
width:10px;
}
span.jPag-sprevious,
span.jPag-sprevious-img{
margin:2px 0px 2px 2px;
font-size:18px;
width:15px;
text-align:right;
}
span.jPag-snext,
span.jPag-snext-img{
margin:2px 4px 2px 0px;
font-size:18px;
width:15px;
text-align:right;
}
ul.jPag-pages li span.jPag-previous-img{
background:transparent url(../images/previous.png) no-repeat center right;
}
ul.jPag-pages li span.jPag-next-img{
background:transparent url(../images/next.png) no-repeat center left;
}
span.jPag-sprevious-img{
background:transparent url(../images/sprevious.png) no-repeat center right;
}
span.jPag-snext-img{
background:transparent url(../images/snext.png) no-repeat center left;
}
----------------------------------------------------------------
sorting function
$('.sortPropertyGenTab').click(function () {
if (PropertyLocation.FlagPropertyGen == '') {
PropertyLocation.FlagPropertyGen = 'desc';
}
var ColName = $(this).attr("id");
PropertyLocation.PropertySortExp = ColName + ' ' + PropertyLocation.FlagPropertyGen;
PropertyLocation.PageNoPropertyGen = 1;
PropertyLocation.PagingGetPhysicalPropertyByModule();
if (PropertyLocation.FlagPropertyGen == 'asc') {
PropertyLocation.FlagPropertyGen = 'desc';
}
else {
PropertyLocation.FlagPropertyGen = 'asc';
}
});
-- =============================================
-- Author:
-- Create date:
-- Description:
-- USP_Location_GetByPhysicalProperty @KeyWord='',@Sort='',@PageNumber=1,@PageSize=5,@LanguageId=1,@CommandCenterId='00000000-0000-0000-0000-000000000000',@CompanyId='00000000-0000-0000-0000-000000000000'
CREATE PROCEDURE [dbo].[USP_Location_GetByPhysicalProperty]
@KeyWord varchar(100),
@Sort varchar(50),
@PageNumber int,
@PageSize int,
@LanguageId varchar(10),
@CommandCenterId uniqueidentifier,
@CompanyId uniqueidentifier
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SqlColumnQuery NVARCHAR(max) =''
DECLARE @SqlWhereQuery NVARCHAR(max) =''
DECLARE @SqlJoinQuery NVARCHAR(max) =''
DECLARE @SqlQueryPaging NVARCHAR(max) =''
DECLARE @find nvarchar(5)
DECLARE @replace nvarchar(5)
--to resove apostrophe appended error
SET @find =''+char(39)+''
SET @replace = ''+char(39)+char(39)+''
SET @Keyword = replace(@Keyword,@find,@replace)
IF(@PageNumber IS NULL)
BEGIN
SET @PageNumber = 1
END
IF(@PageSize IS NULL)
BEGIN
SET @PageSize = 10
END
IF (@Sort = '')
BEGIN
SET @Sort = 'LocationName'
END
SET @SqlColumnQuery ='tblLocation.Name AS LocationName
, tblLocationType_Lang.Name AS LocationTypeName
,tblLocation.LocationId
,((SELECT STUFF((SELECT ''-'' + LS.Name
FROM tblLocationStorage LS
INNER JOIN tblLocationSegment TLS ON TLS.LocationSegmentId = LS.SegmentId
WHERE LS.GroupId = tblinventory.StorageID AND LS.Name != '''' ORDER BY TLS.DisplayOrder
FOR XML PATH ('''')), 1, 1, ''''))) AS StorageName
,tblinventory.StorageID '
SET @SqlJoinQuery =' FROM tblLocationType_Lang
INNER JOIN tblLocationType
ON tblLocationType_Lang.LocationTypeId = tblLocationType.Id and tblLocationType_Lang.LanguageId=1 AND tblLocationType.IsActive = 1
INNER JOIN tblLocationTypeMapping
ON tblLocationType.Id = tblLocationTypeMapping.LocationTypeId AND tblLocationTypeMapping.IsPrimary = 1
INNER JOIN tblLocation
ON tbllocation.LocationId=tblLocationTypeMapping.LocationId
INNER JOIN tblinventory
ON tbllocation.LocationId=tblinventory.StorageLocationID
INNER JOIN tblitem
ON tblinventory.ItemID=tblitem.ID
INNER JOIN tblitemtemplate
ON tblitem.ItemTemplateID=tblitemtemplate.Id
INNER JOIN tblResourceType
ON tblitemtemplate.ResourceTypeId=tblResourceType.ID
WHERE tbllocation.CompanyId='''+Convert(nvarchar(50),@CompanyId)+'''
AND tbllocation.CommandCenterId='''+Convert(nvarchar(50),@CommandCenterId)+'''
AND tblResourceType.IsPhysicalProperty=1'
IF (@KeyWord <> '')
BEGIN
SET @SqlWhereQuery = 'AND (tblLocation.Name LIKE ''%'+ @KeyWord +'%'')'
END
Set @SqlQueryPaging=')T) T1 WHERE ROWNUM BETWEEN ('+Convert(nvarchar(50),@PageNumber)
+' * '+Convert(nvarchar(50),@PageSize) +'+ 1 - '+Convert(nvarchar(50),@PageSize)+')
AND ('+Convert(nvarchar(50),@PageSize)+' * '+Convert(nvarchar(50),@PageNumber)+') '
EXEC ('DECLARE @Count INT
SELECT @Count = COUNT(*) FROM (
SELECT DISTINCT '+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + '
) TTY SELECT * FROM ( SELECT *, ROW_NUMBER() OVER(ORDER BY '+ @Sort+') as RowNum
FROM ( SELECT DISTINCT @Count AS Total,'+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + @SqlQueryPaging)
Print ('DECLARE @Count INT
SELECT @Count = COUNT(*) FROM (
SELECT DISTINCT '+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + '
) TTY SELECT * FROM ( SELECT *, ROW_NUMBER() OVER(ORDER BY '+ @Sort+') as RowNum
FROM ( SELECT DISTINCT @Count AS Total,'+ @SqlColumnQuery + @SqljoinQuery + @SqlWhereQuery + @SqlQueryPaging)
END
------------------------------------------------------------------------------------------------------------------------------------------------
Paging ddl and div
Page Size:
---------------------------------------------------------------------------------------------------------------------------------------------
Paging function jquery
// Get all location by property
GetLocationByProperty: function () {
var data = { keyword: PropertyLocation.KeyWordLocation, sort: PropertyLocation.LocationSortExp, pageNumber: PropertyLocation.PageNumberLocation, pageSize: PropertyLocation.PageSizeLocation }
var pageSize = $('#ddlLocationPopupPaging').val();
$.ajax({
type: "POST",
url: $("#hdnSitePath").val() + 'WebServices/PropertyVerification.asmx/GetLocationByProperty',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (result) {
if (result.d == null || result.d == 'null') {
window.location = $("#hdnSitePath").val() + "Login/Login.aspx";
}
else {
$("#tblLocationProperty tbody").html("");
var str = "";
for (var i = 0; i < result.d.length; i++) {
str += '
str += '';
str += '
str += '
str += '
str += '
str += "
}
$("#tblLocationProperty tbody").html(str);
if (result.d.length > 0) {
PropertyLocation.TotalLocationRec = result.d[0].Total;
}
else {
PropertyLocation.TotalLocationRec = 0;
}
PropertyLocation.PageSizeLocation = pageSize;
PropertyLocation.NumberOfPagesLocation = Math.ceil(PropertyLocation.TotalLocationRec / PropertyLocation.PageSizeLocation);
}
},
error: function (xhr) {
commonNotification.ErrorMessage(commonNotification.Error + xhr.responseText);
}
});
},
// Paging of locations by Property
PagingGetLocation: function () {
PropertyLocation.GetLocationByProperty();
if (PropertyLocation.NumberOfPagesLocation > 1) {
$('#divLocationPopupPaging').show();
$('#divForPageSize').show();
var displayPage = 8;
if (PropertyLocation.NumberOfPagesLocation < displayPage) {
displayPage = PropertyLocation.NumberOfPagesLocation;
}
$("#divLocationPopupPaging").paginate({
count: PropertyLocation.NumberOfPagesLocation,
start: PropertyLocation.PageNumberLocation,
display: displayPage,
border: true,
border_color: '#fff',
text_color: '#fff',
background_color: '#555',
border_hover_color: '#ccc',
text_hover_color: '#000',
background_hover_color: '#fff',
images: false,
mouse: 'press',
onChange: function (page) {
PropertyLocation.PageNumberLocation = page;
PropertyLocation.GetLocationByProperty(); //change
}
});
}
else if (PropertyLocation.NumberOfPagesLocation == 1) {
$('#divLocationPopupPaging').hide();
$('#divForPageSize').show();
}
else {
$('#divLocationPopupPaging').hide();
$('#divForPageSize').hide();
}
},
----------------------------------------------------------------------------------------------------------------------------------------------
DATA Access function
public List
{
try
{
Int32 PageNumber = Convert.ToInt32(pageNo);
Int32 Pagesize = Convert.ToInt32(pageSize);
SqlConnection sqlConnection = Common.Functions.getConnection();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConnection;
cmd.CommandText = "usp_tblMessage_Summary";
cmd.Parameters.AddWithValue("@Keyword", Keyword);
cmd.Parameters.AddWithValue("@GroupID", groupId);
cmd.Parameters.AddWithValue("@CompanyID", CompanyID);
cmd.Parameters.AddWithValue("@CommandCenterID", CommandCenterID);
cmd.Parameters.AddWithValue("@DateFrom", dateFrom);
cmd.Parameters.AddWithValue("@Sort", sort);
cmd.Parameters.AddWithValue("@UserID", UserId);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill((PageNumber * Pagesize - Pagesize), Pagesize, dt);
if (dt.Rows.Count == 0 && PageNumber > 1)
{
PageNumber--;
da.Fill((PageNumber * Pagesize - Pagesize), Pagesize, dt);
}
-------------------------------------------------------------------------------------------------------------------------------------------------
Jquery.Paginate.js
(function ($) {
$.fn.paginate = function (options) {
var opts = $.extend({}, $.fn.paginate.defaults, options);
return this.each(function () {
$this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
var selectedpage = o.start;
$.fn.draw(o, $this, selectedpage);
});
};
var outsidewidth_tmp = 0;
var insidewidth = 0;
var bName = navigator.appName;
var bVer = navigator.appVersion;
if (bVer.indexOf('MSIE 7.0') > 0)
var ver = "ie7";
$.fn.paginate.defaults = {
count: 5,
start: 12,
display: 5,
border: true,
border_color: '#fff',
text_color: '#8cc59d',
background_color: 'black',
border_hover_color: '#fff',
text_hover_color: '#fff',
background_hover_color: '#fff',
rotate: true,
images: true,
mouse: 'slide',
onChange: function () { return false; }
};
$.fn.draw = function (o, obj, selectedpage) {
$this.empty();
if (o.images) {
var spreviousclass = 'jPag-sprevious-img';
var previousclass = 'jPag-previous-img';
var snextclass = 'jPag-snext-img';
var nextclass = 'jPag-next-img';
}
else {
var spreviousclass = 'jPag-sprevious';
var previousclass = 'jPag-previous';
var snextclass = 'jPag-snext';
var nextclass = 'jPag-next';
}
var _first = $(document.createElement('a')).addClass('jPag-first').html('First');
//$(document.createElement('a')).addClass('jPag-first').html('First');
// $('.jPag-first').attr("id", "fgddd");
// $('#fgddd').html('last_french');
if (o.rotate) {
if (o.images) var _rotleft = $(document.createElement('span')).addClass(spreviousclass);
else var _rotleft = $(document.createElement('span')).addClass(spreviousclass).html('«');
}
var _divwrapleft = $(document.createElement('div')).addClass('jPag-control-back');
_divwrapleft.append(_first).append(_rotleft);
var _ulwrapdiv = $(document.createElement('div')).css('overflow', 'hidden');
var _ul = $(document.createElement('ul')).addClass('jPag-pages')
var c = (o.display - 1) / 2;
var first = selectedpage - c;
var selobj;
for (var i = 0; i < o.count; i++) {
var val = i + 1;
if (val == selectedpage) {
var _obj = $(document.createElement('li')).html('' + val + '');
selobj = _obj;
_ul.append(_obj);
}
else {
var _obj = $(document.createElement('li')).html('' + val + '');
_ul.append(_obj);
}
}
_ulwrapdiv.append(_ul);
if (o.rotate) {
if (o.images) var _rotright = $(document.createElement('span')).addClass(snextclass);
else var _rotright = $(document.createElement('span')).addClass(snextclass).html('»');
}
var _last = $(document.createElement('a')).addClass('jPag-last').html('Last');
var _divwrapright = $(document.createElement('div')).addClass('jPag-control-front');
_divwrapright.append(_rotright).append(_last);
//append all:
$this.addClass('jPaginate').append(_divwrapleft).append(_ulwrapdiv).append(_divwrapright);
if (!o.border) {
if (o.background_color == 'none') var a_css = { 'color': o.text_color };
else var a_css = { 'color': o.text_color, 'background-color': o.background_color };
if (o.background_hover_color == 'none') var hover_css = { 'color': o.text_hover_color };
else var hover_css = { 'color': o.text_hover_color, 'background-color': o.background_hover_color };
}
else {
if (o.background_color == 'none') var a_css = { 'color': o.text_color, 'border': '1px solid ' + o.border_color };
else var a_css = { 'color': o.text_color, 'background-color': o.background_color, 'border': '1px solid ' + o.border_color };
if (o.background_hover_color == 'none') var hover_css = { 'color': o.text_hover_color, 'border': '1px solid ' + o.border_hover_color };
else var hover_css = { 'color': o.text_hover_color, 'background-color': o.background_hover_color, 'border': '1px solid ' + o.border_hover_color };
}
$.fn.applystyle(o, $this, a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright);
//calculate width of the ones displayed:
var outsidewidth = outsidewidth_tmp - _first.parent().width() - 3;
// alert(outsidewidth_tmp);
if (ver == 'ie7') {
_ulwrapdiv.css('width', outsidewidth + 72 + 'px');
_divwrapright.css('left', outsidewidth_tmp + 2 + 164 + 'px');
}
else {
_ulwrapdiv.css('width', outsidewidth + 'px');
_divwrapright.css('left', outsidewidth_tmp + 2 + 'px');
}
if (o.rotate) {
_rotright.hover(
function () {
thumbs_scroll_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() + 1;
_ulwrapdiv.scrollLeft(left);
},
20
);
},
function () {
clearInterval(thumbs_scroll_interval);
}
);
_rotleft.hover(
function () {
thumbs_scroll_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() - 1;
_ulwrapdiv.scrollLeft(left);
},
20
);
},
function () {
clearInterval(thumbs_scroll_interval);
}
);
if (o.mouse == 'press') {
_rotright.mousedown(
function () {
thumbs_mouse_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() + 5;
_ulwrapdiv.scrollLeft(left);
},
20
);
}
).mouseup(
function () {
clearInterval(thumbs_mouse_interval);
}
);
_rotleft.mousedown(
function () {
thumbs_mouse_interval = setInterval(
function () {
var left = _ulwrapdiv.scrollLeft() - 5;
_ulwrapdiv.scrollLeft(left);
},
20
);
}
).mouseup(
function () {
clearInterval(thumbs_mouse_interval);
}
);
}
else {
_rotleft.click(function (e) {
var width = outsidewidth - 10;
var left = _ulwrapdiv.scrollLeft() - width;
_ulwrapdiv.animate({ scrollLeft: left + 'px' });
});
_rotright.click(function (e) {
var width = outsidewidth - 10;
var left = _ulwrapdiv.scrollLeft() + width;
_ulwrapdiv.animate({ scrollLeft: left + 'px' });
});
}
}
//first and last:
_first.click(function (e) {
_ulwrapdiv.animate({ scrollLeft: '0px' });
_ulwrapdiv.find('li').eq(0).click();
});
_last.click(function (e) {
_ulwrapdiv.animate({ scrollLeft: insidewidth + 'px' });
_ulwrapdiv.find('li').eq(o.count - 1).click();
});
//click a page
_ulwrapdiv.find('li').click(function (e) {
selobj.html('' + selobj.find('.jPag-current').html() + '');
var currval = $(this).find('a').html();
$(this).html('' + currval + '');
selobj = $(this);
$.fn.applystyle(o, $(this).parent().parent().parent(), a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright);
var left = (this.offsetLeft) / 2;
var left2 = _ulwrapdiv.scrollLeft() + left;
var tmp = left - (outsidewidth / 2);
if (ver == 'ie7')
_ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 52 + 'px' });
else
_ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 'px' });
o.onChange(currval);
});
var last = _ulwrapdiv.find('li').eq(o.start - 1);
last.attr('id', 'tmp');
var left = document.getElementById('tmp').offsetLeft / 2;
last.removeAttr('id');
var tmp = left - (outsidewidth / 2);
if (ver == 'ie7') _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 52 + 'px' });
else _ulwrapdiv.animate({ scrollLeft: left + tmp - _first.parent().width() + 'px' });
}
$.fn.applystyle = function (o, obj, a_css, hover_css, _first, _ul, _ulwrapdiv, _divwrapright) {
obj.find('a').css(a_css);
obj.find('span.jPag-current').css(hover_css);
obj.find('a').hover(
function () {
$(this).css(hover_css);
},
function () {
$(this).css(a_css);
}
);
obj.css('padding-left', _first.parent().width() + 5 + 'px');
insidewidth = 0;
obj.find('li').each(function (i, n) {
// alert(this.offsetLeft);
// alert(n);
// alert(i);
// alert(o.display);
// alert(this.offsetLeft + this.offsetWidth);
if (i == (o.display - 1)) {
outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
// alert(outsidewidth_tmp);
}
// else if (i == 1) {
// outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
// }
// else {
// outsidewidth_tmp = this.offsetLeft + this.offsetWidth;
// }
insidewidth += this.offsetWidth;
})
_ul.css('width', insidewidth + 15 + 'px');
}
})(jQuery);
--------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------
Pstyle.css
.jPaginate{
height:34px;
position:relative;
color:#a5a5a5;
font-size:small;
width:100%;
}
.jPaginate a{
line-height:15px;
height:18px;
cursor:pointer;
padding:2px 5px;
margin:2px;
float:left;
}
.jPag-control-back{
position:absolute;
left:0px;
}
.jPag-control-front{
position:absolute;
top:0px;
}
.jPaginate span{
cursor:pointer;
}
ul.jPag-pages{
float:left;
list-style-type:none;
margin:0px 0px 0px 0px;
padding:0px;
}
ul.jPag-pages li{
display:inline;
float:left;
padding:0px;
margin:0px;
}
ul.jPag-pages li a{
float:left;
padding:2px 5px;
background:#fff !important;
color:#656565 !important;
text-decoration:none;
line-height:17px !important;
border:1px solid #cccccc !important;
}
.jPag-last{background:#fff !important;
color:#656565 !important;
text-decoration:none !important;
line-height:17px !important;
border:1px solid #cccccc !important;}
.jPag-last:hover{ background:#e5e5e5 !important}
.jPag-first{background:#fff !important;
color:#656565 !important;
text-decoration:none !important;
line-height:17px !important;
border:1px solid #cccccc !important;}
.jPag-first:hover{ background:#e5e5e5 !important}
span.jPag-current{
cursor:default;
font-weight:normal;
line-height:17px !important;
height:18px;
background:#e5e5e5 !important;
padding:2px 5px;
margin:2px;
float:left;
}
ul.jPag-pages li span.jPag-previous,
ul.jPag-pages li span.jPag-next,
span.jPag-sprevious,
span.jPag-snext,
ul.jPag-pages li span.jPag-previous-img,
ul.jPag-pages li span.jPag-next-img,
span.jPag-sprevious-img,
span.jPag-snext-img{
height:22px;
margin:2px;
float:left;
line-height:18px;
}
ul.jPag-pages li span.jPag-previous,
ul.jPag-pages li span.jPag-previous-img{
margin:2px 0px 2px 2px;
font-size:12px;
font-weight:bold;
width:10px;
}
ul.jPag-pages li span.jPag-next,
ul.jPag-pages li span.jPag-next-img{
margin:2px 2px 2px 0px;
font-size:12px;
font-weight:bold;
width:10px;
}
span.jPag-sprevious,
span.jPag-sprevious-img{
margin:2px 0px 2px 2px;
font-size:18px;
width:15px;
text-align:right;
}
span.jPag-snext,
span.jPag-snext-img{
margin:2px 4px 2px 0px;
font-size:18px;
width:15px;
text-align:right;
}
ul.jPag-pages li span.jPag-previous-img{
background:transparent url(../images/previous.png) no-repeat center right;
}
ul.jPag-pages li span.jPag-next-img{
background:transparent url(../images/next.png) no-repeat center left;
}
span.jPag-sprevious-img{
background:transparent url(../images/sprevious.png) no-repeat center right;
}
span.jPag-snext-img{
background:transparent url(../images/snext.png) no-repeat center left;
}
----------------------------------------------------------------
sorting function
$('.sortPropertyGenTab').click(function () {
if (PropertyLocation.FlagPropertyGen == '') {
PropertyLocation.FlagPropertyGen = 'desc';
}
var ColName = $(this).attr("id");
PropertyLocation.PropertySortExp = ColName + ' ' + PropertyLocation.FlagPropertyGen;
PropertyLocation.PageNoPropertyGen = 1;
PropertyLocation.PagingGetPhysicalPropertyByModule();
if (PropertyLocation.FlagPropertyGen == 'asc') {
PropertyLocation.FlagPropertyGen = 'desc';
}
else {
PropertyLocation.FlagPropertyGen = 'asc';
}
});