Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I write code for data table and pagination feature, it is working for a particular page. Now I want to make this code for common to multiple page.
But not able to do. plz suggest me the require change in my code. my code is as follow:

C#
<script type="text/javascript" charset="utf-8">

            $.fn.dataTableExt.oPagination.iTweenTime = 100;

            $.fn.dataTableExt.oPagination.scrolling = {
                "fnInit": function ( oSettings, fnCallbackDraw )
                {
                    var nPaging = oSettings.anFeatures.p;

                    /* Store the next and previous elements in the oSettings object as they can be very
                     * usful for automation - particularly testing
                     */
                    oSettings.nPrevious = document.createElement( 'div' );
                    oSettings.nNext = document.createElement( 'div' );

                    if ( oSettings.sTableId !== '' )
                    {
                        nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' );
                        oSettings.nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
                        oSettings.nNext.setAttribute( 'id', oSettings.sTableId+'_next' );
                    }

                    oSettings.nPrevious.className = "paginate_disabled_previous";
                    oSettings.nNext.className = "paginate_disabled_next";

                    oSettings.nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
                    oSettings.nNext.title = oSettings.oLanguage.oPaginate.sNext;

                    nPaging.appendChild( oSettings.nPrevious );
                    nPaging.appendChild( oSettings.nNext );
                    $(nPaging).insertAfter( oSettings.nTable );

                    $(oSettings.nPrevious).click( function() {
                        /* Disallow paging event during a current paging event */
                        if ( typeof oSettings.iPagingLoopStart != 'undefined' && oSettings.iPagingLoopStart != -1 )
                        {
                            return;
                        }

                        oSettings.iPagingLoopStart = oSettings._iDisplayStart;
                        oSettings.iPagingEnd = oSettings._iDisplayStart - oSettings._iDisplayLength;

                        /* Correct for underrun */
                        if ( oSettings.iPagingEnd < 0 )
                        {
                          oSettings.iPagingEnd = 0;
                        }

                        var iTween = $.fn.dataTableExt.oPagination.iTweenTime;
                        var innerLoop = function () {
                            if ( oSettings.iPagingLoopStart > oSettings.iPagingEnd ) {
                                oSettings.iPagingLoopStart--;
                                oSettings._iDisplayStart = oSettings.iPagingLoopStart;
                                fnCallbackDraw( oSettings );
                                setTimeout( function() { innerLoop(); }, iTween );
                            } else {
                                oSettings.iPagingLoopStart = -1;
                            }
                        };
                        innerLoop();
                    } );

                    $(oSettings.nNext).click( function() {
                        /* Disallow paging event during a current paging event */
                        if ( typeof oSettings.iPagingLoopStart != 'undefined' && oSettings.iPagingLoopStart != -1 )
                        {
                            return;
                        }

                        oSettings.iPagingLoopStart = oSettings._iDisplayStart;

                        /* Make sure we are not over running the display array */
                        if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
                        {
                            oSettings.iPagingEnd = oSettings._iDisplayStart + oSettings._iDisplayLength;
                        }

                        var iTween = $.fn.dataTableExt.oPagination.iTweenTime;
                        var innerLoop = function () {
                            if ( oSettings.iPagingLoopStart < oSettings.iPagingEnd ) {
                                oSettings.iPagingLoopStart++;
                                oSettings._iDisplayStart = oSettings.iPagingLoopStart;
                                fnCallbackDraw( oSettings );
                                setTimeout( function() { innerLoop(); }, iTween );
                            } else {
                                oSettings.iPagingLoopStart = -1;
                            }
                        };
                        innerLoop();
                    } );

                    /* Take the brutal approach to cancelling text selection */
                    $(oSettings.nPrevious).bind( 'selectstart', function () { return false; } );
                    $(oSettings.nNext).bind( 'selectstart', function () { return false; } );
                },

                "fnUpdate": function ( oSettings, fnCallbackDraw )
                {
                    if ( !oSettings.anFeatures.p )
                    {
                        return;
                    }

                    oSettings.nPrevious.className =
                        ( oSettings._iDisplayStart === 0 ) ?
                        "paginate_disabled_previous" : "paginate_enabled_previous";

                    oSettings.nNext.className =
                        ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
                        "paginate_disabled_next" : "paginate_enabled_next";
                }
            }
            jQuery.fn.dataTableExt.aTypes.push(
                function ( sData )
                {
                    var sValidChars = "0123456789-,";
                    var Char;
                    var bDecimal = false;

                    /* Check the numeric part */
                    for ( i=0 ; i<sData.length ; i++ )
                    {
                        Char = sData.charAt(i);
                        if (sValidChars.indexOf(Char) == -1)
                        {
                            return null;
                        }

                        /* Only allowed one decimal place... */
                        if ( Char == "," )
                        {
                            if ( bDecimal )
                            {
                                return null;
                            }
                            bDecimal = true;
                        }
                    }

                    return 'numeric-comma';
                }
            );

            jQuery.fn.dataTableExt.oSort['numeric-comma-asc']  = function(a,b) {
                var x = (a == "-") ? 0 : a.replace( /,/, "." );
                var y = (b == "-") ? 0 : b.replace( /,/, "." );
                x = parseFloat( x );
                y = parseFloat( y );
                return ((x < y) ? -1 : ((x > y) ?  1 : 0));
            };

            jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
                var x = (a == "-") ? 0 : a.replace( /,/, "." );
                var y = (b == "-") ? 0 : b.replace( /,/, "." );
                x = parseFloat( x );
                y = parseFloat( y );
                return ((x < y) ?  1 : ((x > y) ? -1 : 0));
            };


            $(document).ready(function() {
                $('#preactivitymanagementtable').dataTable( {
                        "sPaginationType": "scrolling",
                        "bAutoWidth": false,

                } );

            } );

        </script>
Posted
Comments
Sudhakar Shinde 19-Jul-13 1:40am    
You need to mention the problem you are facing. Nobody will debug your code to find out the error and solution for it. If you specify exact error you are getting then we can help you to resolve. Simply saying not able to do is not going to help.
RaginiSinha 19-Jul-13 2:24am    
actually a want to make a common function in separate file , and to call that function on the page where i want to apply this feature.
but don't know how to do that..
RaginiSinha 19-Jul-13 2:25am    
what should i mention

$(document).ready(function() {
$('#preactivitymanagementtable').dataTable( {
"sPaginationType": "scrolling",
"bAutoWidth": false,

} );

here as a dynamic selector according to the page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900