This is a migrated thread and some comments may be shown as answers.

[Solved] Telerik Grid Row Custom Formatting on either bit/int/string field pt2

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lp1
Top achievements
Rank 1
Lp1 asked on 13 May 2011, 09:39 AM
My post

Atanas with point 4 I had already covered exactly what you said in the edit of that post but even after making sure it would only look affect the name col and not the ID col it would still colour the other rows in the name col.
So row 1 col 2 = One but row 2 col 2 = Two
Yet both row 1 col 2 and row 2 col 2 would be red

This is why I said I thought it was broken since the 2nd nested "if" was conditional on "One" not "Two" yet it was affecting both.

In regards too "As for the rest points - I find it very difficult to follow your point."
I don't know how much clearer I can make em but I'll try.
"3. I was explaining that I have no experience before using server side and I've only done ajax so was asking if there was any link or info in regards from switching from using 1 to the other. (the rest was just me thinking out loud that my project will be ok with server side since it's only for max of 5 users to use and not 100's like some of my other projects)"

3. Basically I have only used ajax binds before
The demo's and help sections lacks/doesn't go into very much detail in regards to server side
So if there any other site or info you can provide for server side?
I was specifically asking if it was directed towards ajax users switching to server side.
I provided in the example proj I uploaded how I attemped too setup the grid with server side and was hoping you could look at that and correct what I did wrong.

5. Last time you talked about it you only touched on the 1st point I had made in regards to dates with jscript so I tried to re-explain the rest of what I said but doesn't seem like that helped so I hope this does.
//.ClientTemplate("<# { #><span style='color:[object]'>[object]</span><# } #>")
I was trying to see if there was anyway to use jscript to feed an object into 'color: [object]' but to have this affect the whole cell or just text and if I had to do it the same way as shown above then to also feed the actual date value into the 2nd [object]

Finally with point 6. This is an alternative way I found to get around it would allowed me to use ajax but I was having problems with my date conditions so was hoping you could have a look at it to see if you could spot where I was going wrong.

Your Reply

Hi Lp1,

Unfortunately we are not making any progress with this forum thread. The attached project shows how only the first cell is colored which means that the CellAction works as expected.

I am locking this thread as I don't think we can add anything useful to it.

If you experience other problems you may consider opening another forum thread with the following things present:

1) A sample application showing the problem
2) Clear explanation what the expected behavior is. 

Regards,

Atanas Korchev
the Telerik team

My Reply

1. I provided a sample project and on that same post I provided the project I also very shortly after providing it added in an edit to the post explaining a code change as you can see below

"4. I've made some changes and tried out a number of different things but so far with using the example project you sent I found that cell action didn't seem to function correctly and that it didn't seem to like how I was setting up the database connection (since it didn't display any data or indication that there was any data in the database) to try it out on another page but in a way similar to what I would end up doing in my actual project, So I've attached the updated example project with what I tested so you can see exactly what the problems are.
Edit:-Changed a bit of cell action and got it to only colour the whole col instead of all col and all rows.

.CellAction(cell =>
          {
              if (cell.Column.Title == "Name")
              {
                  if (cell.DataItem.Name == "One")
                  {
                      cell.HtmlAttributes["style"] = "background:red";
                  }
              }
          })
"

Following this you said and asked

4) The CellAction works as designed even in your modified project. Also it has nothing to do with database connections. The Grid does not access your database in any way. It works with the provided IEnumerable or IQueryable. Again I don't see any problem with the attached project. The grid works as told so:
   - make all cells of the first row red (set the background of the TD elements to red)
   - make the entire second row grey (set the background of the TR element to grey)

You have also added this comment:

"//This function seems broken since it doesn't affect a single cell but instead the whole row and if set to "One" would affect row 1 and 2 but if set too "Two" would only affect row 2"

This is of course expected. RowAction is raised for every single row (hence its name). Setting the HtmlAttributes will apply them to the TR element rendered for the grid.

I suggest you tell us what the expected result is so I can explain why the current code does not achieve it. Attaching a screenshot of the desired outcome would be of help.

So I went on to explain in more detail what I was expecting

4. Well I'm expecting cellaction to only affect a single cell not the whole col or the whole row, as you can see in my could its been setup to only turn the 1st record and 2nd col which is the name col red, what I don't want it to do is change the whole name col red or what it seems to be everything under the result which makes the colour change requirement.

So is this not possible with cellaction?

and

Atanas with point 4 I had already covered exactly what you said in the edit of that post but even after making sure it would only look affect the name col and not the ID col it would still colour the other rows in the name col.
So row 1 col 2 = One but row 2 col 2 = Two
Yet both row 1 col 2 and row 2 col 2 would be red

This is why I said I thought it was broken since the 2nd nested "if" was conditional on "One" not "Two" yet it was affecting both.

New reply now

As you can see from above I stated exactly what I was expecting which to summarise is -
I'm trying to cellaction to affect only a single cell
Not the whole Row - solved in the edit I did for the post where I provided a test project which also including a small code block like you can see again below

"Edit:-Changed a bit of cell action and got it to only colour the whole col instead of all col and all rows.
.CellAction(cell =>
          {
              if (cell.Column.Title == "Name")
              {
                  if (cell.DataItem.Name == "One")
                  {
                      cell.HtmlAttributes["style"] = "background:red";
                  }
              }
          })
"

Not the Column - this was the main problem which is what I repeatedly explained
I made the colouring condition based on if the name col had a value of One and was expecting it to only colour that single cell
not the whole col since the below row had the value "Two" which doesn't fit the condition.

Now you asked for a sample project to show the problem well I've already provided that on this topic
http://www.telerik.com/community/forums/aspnet-mvc/grid/telerik-grid-row-custom-formatting-on-either-bit-int-string-field.aspx#1642290
Along with the above edit which came along with said proj it means instead of having to reupload the same project which only included 2-3 changed lines of code I added the code block so unless your not allowed to copy and paste off this forum then I don't see why such a small change would require a new upload and you haven't explained why either so all I can assume from this is you missed the edit.

If there is anything else you didn't understand about my last post of the previous topic like in regards to point 3 + 5 well can you please explain where the confusion lies since it's kinda vague saying "As for the rest points - I find it very difficult to follow your point."

3. = asking for addition help in regards to setting up server side binding due to 2 previous links provided limited detail
Plus in my sample project as I already stated I provided an example of me trying to test thing out and it proving unsuccessful
This is also something you seem to have missed.

5. = alternative ways to produce the end result
I clearly stated I've stopped looking at doing the calc in jscript.
I was now looking at and asking about way to produce end result via Client Template as you can see from what I will paste below from a previous post I made.

//.ClientTemplate("<# { #><span style='color:[object]'>[object]</span><# } #>")
I was trying to see if there was anyway to use jscript to feed an object into 'color: [object]' but to have this affect the whole cell or just text and if I had to do it the same way as shown above then to also feed the actual date value into the 2nd [object]

If there is anything I have missed in this or you still need more detail for something then please be more specific.

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 13 May 2011, 09:48 AM
Hi Lp1,

I said many times why the previous application didn't work the way you expected and also attached a modified version which shows how to set the background color of a single cell.

I won't continue the same discussion again. I have already attached a working sample project to the previous thread which shows how to apply background color to a single cell only.

This would be my last reply discussing CellAction and background colors. 

I am closing this thread again as it is exact duplicate of the previous. Please do not start yet another thread discussing the same non-existing problem.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Lp1
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or