tags:

views:

35

answers:

1

i need to place defalut text to all rows for perticular column in jquery grid?

can anybody help me out..

thanks

+1  A: 

Apply a class name to the cells that require a default text -in this example the class name is 'placeholder'- and target that with jQuery:

$(document).ready(
  function() {
    $('td.placeholder').text('this message to be shown');
  }
)

It's untested, but I think it'll do what you want, unless you need to use specific html for some reason? In which case:

    $('td.placeholder').html('<span class="default_text">this message to be shown</span>');

should work instead.


Edited in response to question (in comments):

if I need to perform only for one last cell? thanks – kumar

If you only need to perform this action on one particular cell you can either assign an id or a class to that cell, an id is/must be/should be unique in the document so only one element can have any id. A class is probably still the easiest solution, since it allows for later re-use of the same code/jQuery function. Still, to advise:

// to select <td> element of a particular id:
$('td#element_id').text('this message to be shown');

// to select the last cell:
$('td:last').text('this message to be shown');

// to select only the last cell that has a particular class-name 'placeholder':
$('td.placeholder:last').text('this message to be shown');

Incidentally, you might like to read the jQuery docs, over at: docs.jquery.com/

David Thomas
Do I have to .each() or will this do the job iterating through all of them?
Mahesh Velaga
@Mahesh - This will perform the action on **all** cells with that class.
Nick Craver
if I need to perform only for one last cell? thanks
kumar
@Nick: awesome, thanks :)
Mahesh Velaga
Thanks @Nick, hadn't seen the reply 'til now.
David Thomas
@Kumar, see the updated answer (below the horizontal rule), for an answer to your question in the comments.
David Thomas
Thank rice..But I am not able to see the default text in jquery grid row.. that i have 5 rows in jquery grid but at the last column for each row I am not seeing this text..$('#table td.Myclassname:last').text('this message to be shown');is this right what I am doig there?
kumar
@Kumar: show me the generated html for the page (view source -> copy the html for the table -> edit this question and add the code) and I'll see if anything stands out. Although looking at your comment you're selecting the last `td` element with class `Myclassname` that's a child of an element with the `id` of 'table'. Two things: do you *have* an element with an `id` of table, and is your classname spelled correctly?
David Thomas
I have an id of table..thanks ricebowl,
kumar