0

I'm trying to add a new row after a specific row in a ASP.NET DataGrid with JQuery. I already added a new row after every row doing:

$('<tr class="sep"><td  colspan="13"></td></tr>').insertAfter('tr.fila');

but now I want to add the row after some specific rows and not after all of them.

Can somebody give me a hand with this?

1 Answer 1

1

We can't really answer this one unless we know what the criteria is for the specific rows you need to target.

Here are some jQuery selectors that may be of use to you:

http://api.jquery.com/?s=nth

If it's based on a data scenario, you can add a class to the row/cell through DataBound events etc. and target that class with a selector. Or if it's something like every other row, you could do it simply in jQuery.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. It's based on a data scenario. What I intend to do is to "group" the rows based on, for example, client. If I have 5 rows of the same client, then I want them to be displayed one after another. But, when the client changes, I want to separate it including via JQuery an extra empty row. The thing is, I have CSS classes for both kind of rows, the "data" row (in the example class "fila") and the empty row (class "sep"). If I set in DataBound event for the rows with client "Pepsi" a class, wouldn't it replace the original "fila" class?
In light of the above, I would in a DataBound event, loop through the rows, detect when a client id is changing and apply a data- attribute e.g. data-lastrowofclient=true to the last row of the client. You can then, through jQuery look for that attribute $("tr[data-lastrowofclient=\"true\"]").after("<tr><!--new row --></tr")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.