Utilize a custom JQuery script on designated grid displays

I am facing a challenge in implementing a JQuery script on specific Gridviews within my page. The issue lies in the fact that the script is currently being applied to all Gridviews on the page, and I need a way to specify which grids it should apply to.

The Script I am utilizing was authored by Ryan Zielke.

$.fn.tablePagination = function (settings) {
    var defaults = {
        firstArrow: (new Image()).src = "./images/first.gif",
        prevArrow: (new Image()).src = "./images/prev.gif",
        lastArrow: (new Image()).src = "./images/last.gif",
        nextArrow: (new Image()).src = "./images/next.gif",
        rowsPerPage: 5,
        currPage: 1,
        optionsForRows: [5, 10],
        ignoreRows: []
    };
    settings = $.extend(defaults, settings);

    return this.each(function () {
        var table = $(this)[0];
        // Remaining code remains the same
    })
};

})(jQuery);

The script is activated client side using the following function:

       $('table').tablePagination({});

It also includes some CSS styling as shown below:

      #testTable { 
        width : 300px;
        margin-left: auto; 
        margin-right: auto; 
      }

       // Additional CSS rules remain unchanged

To target a specific gridview, I have attempted the following modifications:

Changing the clientside script to:

    $('#GridviewName').tablePagination({});

I also tried updating the script itself to target a particular class like this:

var possibleTableRows = $.makeArray($('.pagingclass tbody tr', table));

Here, I aimed to define a class and then assign that CSS class to the gridview in order to exclusively apply the script to that specific gridview. Unfortunately, these attempts did not yield the desired outcome.

I'm unsure of the best approach or if achieving this customization is feasible. Any guidance on this matter would be extremely valuable.

Answer №1

It is recommended to utilize the ID of the gridview element

$('#<%=GridViewID.ClientID%>').tablePagination({});

By using $('table').tablePagination({});, you will be selecting all tables within the page. When examining the HTML generated by a gridview control, you'll notice that it resembles the specified ID in the control but isn't an exact match. Hence, it's crucial to employ the client ID reference instead of something like

$('#GridViewID').tablePagination({});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying the Polymer Paper spinner when the page is still loading

How can I make the polymer paper spinner display while the body tag is set to unresolved? I'm experiencing a brief blank screen before the page finishes loading. I'm feeling lost and unsure of how to begin. Check out the Polymer Project documen ...

The .NET Portability Analyzer was experiencing difficulties running on the Microsoft Windows Server 2016 (Datacenter) platform

My current task involves running the .NET Portability Analyzer scan on a Microsoft Windows Server 2016 (Datacenter) system This particular datacenter is where an ASP.NET Web Forms application is hosted on IIS version 10 I was informed that I could acquir ...

In search of assistance with a persistent react.js error plaguing my work

I keep encountering an error whenever I run npm start on a new project. Does anyone have any insight on how to resolve this issue? The problem might lie within the project dependency tree rather than being a bug in Create React App. Here is what you can ...

What is the process for resizing a texture render target following a window resize event?

My intention was to improve the texture quality, but instead of achieving my goal, I encountered an issue where the same texture is being stretched over a larger area, resulting in unwanted staircase artifacts. I tried updating various elements like camera ...

How to Use C# to Redirect Between ASPX Pages

My application consists of two .aspx pages. The second page includes a dropdownlist that is bound to the database using a collection. I am trying to redirect from the second page to the first page by using the following code: Response.Redirect("~/Admin/Ho ...

information directed towards particular positions on a meter

I am in the process of creating a dashboard skin that receives data from a game via a plugin. I have encountered a problem with the RPM gauge. The issue is that the angle from 0 to 5 on the gauge is smaller than the angle from 5 to 10. I am attempting to s ...

What is the best way to transfer data between files in Python?

My website code is (ser.html) <div> <a v-bind:href="'ser/'+post.name"> {{post.name}}</a> </div> I am trying to transfer post.name data from this file to another one (det.html). In my views.py file: from django.shortcut ...

Choose a specific example using the class name in nicEdit

Is there a way to select an instance using nicEdit based on its class name rather than just its id? For example: <div class="myInstance1"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna dolor, faucibus ac, iaculis non, cursus et ...

Incorporating ContentPlaceHolder in ASP.NET MasterPage

For my In-Application CMS project, I am considering allowing users to upload an HTML and a CMS file as the Masterpage. One solution I have in mind is to have users include Pre-Defined Tags within their HTML files, which I can then replace with ContentPlac ...

Tips for regaining control of autocomplete if a user has entered an incorrect value

I am working with a table that contains rows with textboxes that have autocomplete functionality. In the server-side code, the structure looks like this: <td><asp:TextBox ID="tbNumber" runat="server" onfocus="AttachNumbers(this)" /></td> ...

What is the best way to modify a React ref when the child elements of ref.current are altered?

I'm currently utilizing React refs for managing click events outside of an element. import { useEffect } from 'react'; export const useClickOutside = (ref, callback = () => {}) => { const handleClick = e => { if (ref.current ...

Utilizing jQuery Mobile in combination with jQuery.mobile.back() enhances the user

On my website, I implemented a Back button: <a href="javascript:void(0)" data-role="button" data-inline="true" data shadow='true' data-corners='true' id='goBackfromExerc' onClick="goBackfromExerc()">Yes</a> ...

Table with Typewriter Style CSS Animation

I came across an interesting typewriter effect implementation using CSS in an article on CSS Tricks I decided to play around with it and see if I could apply it to a hero image, which I found an example of on Codepen However, I noticed that the blinking ...

Can the Bootstrap grid be arranged vertically?

I'm finding it difficult to work on a project with Bootstrap's horizontal grid system. What I want to achieve is to have my page divided into 4 sections, with the left side blocks having equal height and the right side blocks having varying heigh ...

Adjusted position of the viewport if the DOM element containing the renderer is not located at the top of the display

I've come across an issue with a three.js scene within an Angular custom directive in the view. At the top, there's a navigation bar for switching between views (pretty standard so far). I set up a simple scene with a cube and basic camera rotati ...

What is the best way to retrieve the content of a p tag in React?

How can I access the content of a p tag within an obj and render it through props without using the dangerouslySetInnerHTML method? let content = { para: `<p>A listing page is the public view of a listing. It should informations be designed to ...

`ASP.Net MVC sophisticated user interface and ModelBinder authentication`

While we understand that authorization is a crucial aspect, we strive to keep business logic separate from our views. However, I am still searching for a graceful way to filter UI components (such as widgets, form elements, tables, etc) based on the curre ...

Overlap one element entirely with another

Currently, I am working on a way for an element called overlayElement to completely cover another element known as originalElement. The overlayElement is an iFrame, but that detail may not be significant in this scenario. My goal is to ensure that the over ...

Tips for choosing records using sequelize starting from the startdate up until but not including the enddate

My challenge involves working with datasets that include a 'timestamp' attribute. I am looking to efficiently select datasets that have timestamps starting from a specific start date up until an end date, without including the end date itself. In ...

Exploring ways to retrieve query parameters and search params within a loader function in React Router version 6

I set up a route configuration like this: const router = createBrowserRouter([ { path: "/", element: <Layout />, children: [ { index: true, element: <Home /> }, { path: "contacts", element: <Cont ...