Dear Great Gurus
I am using Classic ASP Datatables with json to fetch data .
My issues are
1) Datatables are not Refreshed.
2) A Very Slow response of Datatables(I have 10000+ Records in the table.)
Please help me in winning this situation..Thanks in Advance
Below is my Code.
[CODE]
<script type="text/javascript" charset="utf-8">
var oCache = {
iCacheLower: -1
};
function fnSetKey( aoData, sKey, mValue )
{
for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name == sKey )
{
aoData[i].value = mValue;
}
}
}
function fnGetKey( aoData, sKey )
{
for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name == sKey )
{
return aoData[i].value;
}
}
return null;
}
function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
var iPipe = 20;
var bNeedServer = false;
var sEcho = fnGetKey(aoData, "sEcho");
var iRequestStart = fnGetKey(aoData, "iDisplayStart");
var iRequestLength = fnGetKey(aoData, "iDisplayLength");
var iRequestEnd = iRequestStart + iRequestLength;
oCache.iDisplayStart = iRequestStart;
/* outside pipeline? */
if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
{
bNeedServer = true;
}
if ( oCache.lastRequest && !bNeedServer )
{
for( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" )
{
if ( aoData[i].value != oCache.lastRequest[i].value )
{
bNeedServer = true;
break;
}
}
}
}
oCache.lastRequest = aoData.slice();
if ( bNeedServer )
{
if ( iRequestStart < oCache.iCacheLower )
{
iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
if ( iRequestStart < 0 )
{
iRequestStart = 0;
}
}
oCache.iCacheLower = iRequestStart;
oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
fnSetKey( aoData, "iDisplayStart", iRequestStart );
fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
$.getJSON( sSource, aoData, function (json) {
/* Callback processing */
oCache.lastJson = jQuery.extend(true, {}, json);
if ( oCache.iCacheLower != oCache.iDisplayStart )
{
json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
}
json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
fnCallback(json)
} );
}
else
{
json = jQuery.extend(true, {}, oCache.lastJson);
json.sEcho = sEcho; /* Update the echo for each response */
json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
json.aaData.splice( iRequestLength, json.aaData.length );
fnCallback(json);
return;
}
}
$(window).bind('resize', function () {
oTable.fnAdjustColumnSizing();
} );
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bDeferRender": true,
"iDisplayLength": 10,
"bServerSide": true,
"sAjaxSource": "Test.asp",
"sScrollY": 400,
//"sScrollX": "500px",
"sDom": "frtiS",
"bDeferRender": true,
"bJQueryUI": true,
"fnServerData": fnDataTablesPipeline,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
//"sSwfPath": "extras/media/swf/copy_csv_xls_pdf.swf"
}
} );
} );
</script>
[/CODE]
Classic ASP Code : TEST.asp
[CODE]
<%
sEcho = Cint(Request("sEcho"))
iDisplayLength = Cint(Request("iDisplayLength"))
iDisplayStart = Cint(Request("iDisplayStart"))
sSearch = trim(UCASE(Request("sSearch")))
sessid = Session("EID")
strWhere = " WHERE COL1 LIKE '%" & sSearch & "%' OR "
strWhere = strWhere & " COL2 LIKE '%" & sSearch & "%' OR "
strWhere = strWhere & " COL3 LIKE '%" & sSearch & "%' OR "
'strWhere = strWhere & " COL4 LIKE '%" & sSearch & "%' OR "
'strWhere = strWhere & " COL5 LIKE '%" & sSearch & "%' OR "
strWhere = strWhere & " COL6 LIKE '%" & sSearch & "%'"
for k=0 to 3
if Request("bSortable_" & k)="true" then
order = order & Request("iSortCol_" & k) & " " & Request("sSortDir_" & k)
end if
next
order = Replace(order,"0",", COL1")
order = Replace(order,"1",", COL2")
order = Replace(order,"2",", COL3")
order = Replace(order,"3",", COL4")
'order = Replace(order,"4",", COL5")
'order = Replace(order,"4",", COL6")
if Len(order) <> 0 then
order = Right(order, Len(order)-1)
Else
End If
strOrderBy = " ORDER BY " & order
if isnull(trim(order)) or trim(order) = "" then
strOrderBy = " ORDER BY 1"
Else
End If
Set Session("objConn") = Server.CreateObject("ADODB.Connection")
strConnection = "Provider=MSDAORA;Data Source=PERS;User Id=ITMAN;Password=ITMAN;"
Session("objConn").open strConnection
SQL = "select COL1, COL2, , COL3, COL4, COL5,COL6 from PERSTBL " & strWhere & " and IS_DELETED <> 'Y' "& strOrderBy
Set rs = Session("objConn").Execute(SQL)
'Response.Write sql
'Response.Write date()
'Response.Write tstr
iTotalDisplayRecords = 0
if rs.eof = false then
do while not rs.eof
iTotalDisplayRecords = iTotalDisplayRecords + 1
rs.movenext
loop
rs.movefirst
end if
SQL2 = "SELECT count(*) FROM PERSTBL where IS_DELETED <> 'Y'"
Set rs2 = Session("objConn").Execute(SQL2)
iTotalRecords = rs2(0)
%>
{"sEcho": <%=sEcho%>, "iTotalRecords": <%=iTotalRecords%>, "iTotalDisplayRecords": <%=iTotalDisplayRecords%>, "aaData": [
<% i= 0
if rs.eof = false then
rs.move(iDisplayStart)
do while i < iDisplayLength and not rs.eof
tstr = Left(rs("COL5"),100)
if isnull(rs("DEP_ON_LIVE")) or rs("DEP_ON_LIVE") = "N" then
set_typ = "<font color=#FF0000> - (U)</font>"
Else
End If
if rs("DEP_ON_LIVE") = "Y" then
set_typ = "<font color=#FF0000> - (P)</font>"
set_typ1 = "<a href=Patch_Revert.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">REVERT</a> " & set_typ
Else
set_typ1 = "<a href=patch_add_to_live.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">TO LIVE</a> | <a href=Patch_Revert.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">REVERT</a> " & set_typ
End If
if rs("IS_REVERTED") = "Y" then
set_typ = "<font color=#FF0000> - (R)</font>"
set_typ1 = "<a href=patch_add_to_live.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">TO LIVE</a> | <a href=Patch_Revert.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">REVERT</a> " & set_typ
Else
End If
aaData = aaData + "['<a href=Edit_Patch.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") &">" & rs("COL1") & "</a>','"& rs("COL3") &"','" & rs("COL4") & "','" & rs("COL2") & "','<a href=Edit_Patch.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") &">" & tstr & "</a>','"& set_typ1 &"'],"
aaData = Replace(aaData,"'",chr(34))
rs.movenext
i=i+1
loop
aaData = Left(aaData,Len(aaData)-1)
else
aaData = ""
end if
response.write aaData & "] }"
%>
[/CODE]
I am using Classic ASP Datatables with json to fetch data .
My issues are
1) Datatables are not Refreshed.
2) A Very Slow response of Datatables(I have 10000+ Records in the table.)
Please help me in winning this situation..Thanks in Advance
Below is my Code.
[CODE]
<script type="text/javascript" charset="utf-8">
var oCache = {
iCacheLower: -1
};
function fnSetKey( aoData, sKey, mValue )
{
for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name == sKey )
{
aoData[i].value = mValue;
}
}
}
function fnGetKey( aoData, sKey )
{
for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name == sKey )
{
return aoData[i].value;
}
}
return null;
}
function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
var iPipe = 20;
var bNeedServer = false;
var sEcho = fnGetKey(aoData, "sEcho");
var iRequestStart = fnGetKey(aoData, "iDisplayStart");
var iRequestLength = fnGetKey(aoData, "iDisplayLength");
var iRequestEnd = iRequestStart + iRequestLength;
oCache.iDisplayStart = iRequestStart;
/* outside pipeline? */
if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
{
bNeedServer = true;
}
if ( oCache.lastRequest && !bNeedServer )
{
for( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" )
{
if ( aoData[i].value != oCache.lastRequest[i].value )
{
bNeedServer = true;
break;
}
}
}
}
oCache.lastRequest = aoData.slice();
if ( bNeedServer )
{
if ( iRequestStart < oCache.iCacheLower )
{
iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
if ( iRequestStart < 0 )
{
iRequestStart = 0;
}
}
oCache.iCacheLower = iRequestStart;
oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
fnSetKey( aoData, "iDisplayStart", iRequestStart );
fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
$.getJSON( sSource, aoData, function (json) {
/* Callback processing */
oCache.lastJson = jQuery.extend(true, {}, json);
if ( oCache.iCacheLower != oCache.iDisplayStart )
{
json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
}
json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
fnCallback(json)
} );
}
else
{
json = jQuery.extend(true, {}, oCache.lastJson);
json.sEcho = sEcho; /* Update the echo for each response */
json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
json.aaData.splice( iRequestLength, json.aaData.length );
fnCallback(json);
return;
}
}
$(window).bind('resize', function () {
oTable.fnAdjustColumnSizing();
} );
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bDeferRender": true,
"iDisplayLength": 10,
"bServerSide": true,
"sAjaxSource": "Test.asp",
"sScrollY": 400,
//"sScrollX": "500px",
"sDom": "frtiS",
"bDeferRender": true,
"bJQueryUI": true,
"fnServerData": fnDataTablesPipeline,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
//"sSwfPath": "extras/media/swf/copy_csv_xls_pdf.swf"
}
} );
} );
</script>
[/CODE]
Classic ASP Code : TEST.asp
[CODE]
<%
sEcho = Cint(Request("sEcho"))
iDisplayLength = Cint(Request("iDisplayLength"))
iDisplayStart = Cint(Request("iDisplayStart"))
sSearch = trim(UCASE(Request("sSearch")))
sessid = Session("EID")
strWhere = " WHERE COL1 LIKE '%" & sSearch & "%' OR "
strWhere = strWhere & " COL2 LIKE '%" & sSearch & "%' OR "
strWhere = strWhere & " COL3 LIKE '%" & sSearch & "%' OR "
'strWhere = strWhere & " COL4 LIKE '%" & sSearch & "%' OR "
'strWhere = strWhere & " COL5 LIKE '%" & sSearch & "%' OR "
strWhere = strWhere & " COL6 LIKE '%" & sSearch & "%'"
for k=0 to 3
if Request("bSortable_" & k)="true" then
order = order & Request("iSortCol_" & k) & " " & Request("sSortDir_" & k)
end if
next
order = Replace(order,"0",", COL1")
order = Replace(order,"1",", COL2")
order = Replace(order,"2",", COL3")
order = Replace(order,"3",", COL4")
'order = Replace(order,"4",", COL5")
'order = Replace(order,"4",", COL6")
if Len(order) <> 0 then
order = Right(order, Len(order)-1)
Else
End If
strOrderBy = " ORDER BY " & order
if isnull(trim(order)) or trim(order) = "" then
strOrderBy = " ORDER BY 1"
Else
End If
Set Session("objConn") = Server.CreateObject("ADODB.Connection")
strConnection = "Provider=MSDAORA;Data Source=PERS;User Id=ITMAN;Password=ITMAN;"
Session("objConn").open strConnection
SQL = "select COL1, COL2, , COL3, COL4, COL5,COL6 from PERSTBL " & strWhere & " and IS_DELETED <> 'Y' "& strOrderBy
Set rs = Session("objConn").Execute(SQL)
'Response.Write sql
'Response.Write date()
'Response.Write tstr
iTotalDisplayRecords = 0
if rs.eof = false then
do while not rs.eof
iTotalDisplayRecords = iTotalDisplayRecords + 1
rs.movenext
loop
rs.movefirst
end if
SQL2 = "SELECT count(*) FROM PERSTBL where IS_DELETED <> 'Y'"
Set rs2 = Session("objConn").Execute(SQL2)
iTotalRecords = rs2(0)
%>
{"sEcho": <%=sEcho%>, "iTotalRecords": <%=iTotalRecords%>, "iTotalDisplayRecords": <%=iTotalDisplayRecords%>, "aaData": [
<% i= 0
if rs.eof = false then
rs.move(iDisplayStart)
do while i < iDisplayLength and not rs.eof
tstr = Left(rs("COL5"),100)
if isnull(rs("DEP_ON_LIVE")) or rs("DEP_ON_LIVE") = "N" then
set_typ = "<font color=#FF0000> - (U)</font>"
Else
End If
if rs("DEP_ON_LIVE") = "Y" then
set_typ = "<font color=#FF0000> - (P)</font>"
set_typ1 = "<a href=Patch_Revert.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">REVERT</a> " & set_typ
Else
set_typ1 = "<a href=patch_add_to_live.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">TO LIVE</a> | <a href=Patch_Revert.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">REVERT</a> " & set_typ
End If
if rs("IS_REVERTED") = "Y" then
set_typ = "<font color=#FF0000> - (R)</font>"
set_typ1 = "<a href=patch_add_to_live.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">TO LIVE</a> | <a href=Patch_Revert.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") & ">REVERT</a> " & set_typ
Else
End If
aaData = aaData + "['<a href=Edit_Patch.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") &">" & rs("COL1") & "</a>','"& rs("COL3") &"','" & rs("COL4") & "','" & rs("COL2") & "','<a href=Edit_Patch.asp?edit_val=" & rs("COL1") & "&rnum=" & rs("rowid") &">" & tstr & "</a>','"& set_typ1 &"'],"
aaData = Replace(aaData,"'",chr(34))
rs.movenext
i=i+1
loop
aaData = Left(aaData,Len(aaData)-1)
else
aaData = ""
end if
response.write aaData & "] }"
%>
[/CODE]