ASP.NET - how to apply alternate row colors to jqgrid  ASP.NET - how to apply alternate row colors to jqgrid

Asked By neha dhage
21-Oct-10 06:46 AM

hi,
i want to apply alternate row colors to jqgrid.
For this i called function like this

jQuery1(document).ready(function() {

    jQuery1("#list").jqGrid({
      url: 'gridData.aspx?pgName=AdminHome',
      datatype: "json",
      id: "OrderId",
      colNames:  "Order Date", "Order Status"],
      colModel: [{ name: 'OrderDate', index: 'OrderDate', width: 90, align: 'left', sortable: true, sorttype: 'text' },
             { name: 'StatusName', index: 'StatusName', width: 130, align: 'left', sortable: true, sorttype: 'text' },
       ],
      height: 250,
      width: 450,
      mtype: "GET",
      pager: '#pager',
      rowNum: 10,
      rowList: [10, 20, 30],
      repeatitems: false,
      viewrecords: true,
      sortname: 'OrderId',
      sortorder: "desc",
      gridview: true,
     
     gridComplete: function() {
      $('#' + "#list" + ' tr:nth-child(even)').addClass("jqgrow evenTableRow");
      $('#' + "#list" + ' tr:nth-child(odd)').addClass("jqgrow oddTableRow");
      }
    });

list is my jqgrid id.

is this method true.
if yes,then where and how to write css classes "jqgrow evenTableRow" and "jqgrow oddTableRow"

  Anoop S replied to neha dhage
21-Oct-10 06:53 AM
Look at the altRows and altclass http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3Aoptions. Beware of the typically inconsistent capitalization! This does use the jQuery UI theme if you're using jqGrid 3.5 or higher.
  Sagar P replied to neha dhage
21-Oct-10 07:17 AM

Yes your code looks ok...
just add css class like this;

Do one thing right click on your applciation  -> add new item -> add StyleSheet file to your application..
Give a name to file like alternateRow.css
In that file add a class like this;

.evenTableRow
{
background-color:#e8eef4;

}

.oddTableRow
{

background-color:#e8eef4;

}

Then on your page header add this statement to include this file;

<link href="alternateRow.css" rel="stylesheet" type="text/css" />

This will work fine....

Also one thing you have mentioned liek this;

gridComplete: function() {
    $('#' + "#list" + ' tr:nth-child(even)').addClass("jqgrow evenTableRow");
    $('#' + "#list" + ' tr:nth-child(odd)').addClass("jqgrow oddTableRow");
    }

if you get any prob change it like this;

gridComplete: function() {
    $('#' + "list" + ' tr:nth-child(even)').addClass("jqgrow evenTableRow");
    $('#' + "list" + ' tr:nth-child(odd)').addClass("jqgrow oddTableRow");
    }

  neha dhage replied to Sagar P
21-Oct-10 08:00 AM
i done this,but alternate colors are not get applied

jQuery1(document).ready(function() {

jQuery1("#list").jqGrid({

url: 'gridData.aspx?pgName=AdminHome',

datatype: "json",

id: "OrderId",

colNames: [ "Order Date", "Order Amount(in $)"],

colModel: [

{ name: 'OrderDate', index: 'OrderDate', width: 90, align: 'left', sortable: true, sorttype: 'text' },

{ name: 'OrderTotal', index: 'OrderTotal', width: 140, align: 'left', sortable: true, sorttype: 'text' },

],

height: 250,

width: 450,

//autowidth: true,

mtype: "GET",

pager: '#pager',

rowNum: 10,

rowList: [10, 20, 30],

repeatitems: false,

viewrecords: true,

sortname: 'OrderId',

viewrecords: true,

sortorder: "desc",

gridview: true,

gridComplete: function() {

$('#' + "list" + ' tr:nth-child(even)').addClass("jqgrow evenTableRow");

$('#' + "list" + ' tr:nth-child(odd)').addClass("jqgrow oddTableRow");

}

 

});

and added css

.evenTableRow

{

background-color:Red;

}

.oddTableRow

{

background-color:Blue;

}

Create New Account
help
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET
application or web application to consume this service? It is True / False? FALSE How many classes can a single.NET DLL contain? Answer1: As many Answer2: One or more What are cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs. Example a. Static int var / / in c#.net b. static void in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging The control itself will take care of the date display How can you deploy an asp.net application ? You can deploy an ASP.NET Web application using any one of the
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Tracing in ASP.NET? hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution of your ASP.NET application. You can record exception details and program flow in a way that doesn't
session is user based mean u can differentiate login user in different way • Process independent. ASP.NET session state is able to run in a separate process from the ASP.NET host process. If session state is in a separate process, the ASP.NET process can come and go while the session state process remains available. Of course, you ASP, too. • Support for server farm configurations. By moving to an out-of-process model, ASP.NET also solves the server farm problem. The new out-of-process model allows all servers