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

[Solved] Hidden column messes up my grid layout

14 Answers 140 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.
Gerard Eikelboom
Top achievements
Rank 1
Gerard Eikelboom asked on 24 Mar 2011, 05:11 PM
In our grid with detailview when I click on the detailview expand button it messes up the next rows beneath them.
This happens in FF, Chrome, Safari. Not in IE (see picture FF example)
This comes because the mastergrid has a hidden column.
Why do we use the hidden column.

I have a event
events.OnDetailViewExpand("onDetailViewExpand"))

function DetailViewExpand(e) {
    var masterRow = e.masterRow;
  
    var User_ID = masterRow.cells[3].innerHTML;

It's an ID column and need it for the rest of the Grid.
Per row the ID is different.

Is there a way I can do without the hidden column?
Regards,
Gerard

14 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Mar 2011, 05:17 PM
Hello Gerard Eikelboom,

 If your grid is bound via ajax you can use the dataItem JavaScript method.

Regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 24 Mar 2011, 05:42 PM
Atanas,

When i use this
var grid = $('#UsersOverzichtGrid').data('tGrid');
    var tr = $('#UsersOverzichtGrid tbody tr:first');
    var dataItem = grid.dataItem(tr);

in my

.ClientEvents(events => events.OnDetailViewExpand(

 

"onDetailViewExpand"))

 


dataItem = undefined

Grid is filled with all my grid items

Does this work in the onDetailViewExpand??

Regards,
Gerard
0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 09:07 AM
Hello Gerard Eikelboom,

 Yes, it should work provided that the UsersOverzichtGrid grid is ajax bound. You can also use the .data array of the grid which contains all data items to which the grid is currently bound (the current page from the data source).

Regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 25 Mar 2011, 09:25 AM
Atanas,
Hereby a test project.
Still my dataItem is undefined.
I can't use  the data array of the grid because I need to know only the data of the row expanded.

Maybe you see what goes wrong.

In the FleuraProdcuctUserControl.ascx is a method
function onDetailViewExpand(e) {
           var grid = $('#VoorraadGrid').data('tGrid');
           var tr = $('#VoorraadGrid tbody tr:first');
           var dataItem = grid.dataItem(tr);
       }


Regards,
Gerard Eikelboom
0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 11:13 AM
Hi Gerard Eikelboom,

Your code is actually finding the header row of the grid (there are two table elements in the grid when scrolling is enabled). Change it to this:

var tr = $('#VoorraadGrid .t-grid-content tbody tr:first');

Regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 25 Mar 2011, 11:34 AM
Atanas,

This works, I got my dataItems, but only for the first row.

So in my grid if I klik on row number 8 it finds dataItems from the 1st row.
Is that because of  tr:first');?
If so it means I need to know wich row I am clicking on, correct?

Regards,
Gerard

0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 11:43 AM
Hello Gerard Eikelboom,

 Yes, tr:first means first tr (row). The OnDetailViewExpand however passes the currently expanding row in its event arguments - e.masterRow. You can pass that to the dataItem method.

Kind regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 25 Mar 2011, 12:39 PM
Atanas,

When I use the e.MasterRow The columns I want to read must be in the Grid.
What I do is I fill the Id column in my model return it to the Grid. But I don't want the column in the Grid. So I can't use the e.masterRow for reading the ID because it's not there.
What I can do is read the Grid.data items (collection). get  the e.masterRow
and match on the columns known in the masterRow by itteration through that collection.
When found get the ID and continue.

What do you think

Regards,
Gerard
0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 02:22 PM
Hello Gerard Eikelboom,

 I am not sure I understand why you can't use e.masterRow. Every row has a corresponding data item which can be retrieved by passing the row to the dataItem JavaScript routine.

Greetings,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 25 Mar 2011, 02:37 PM
Atanas,

example: my Model: ID = 1
                                FirstName = Atanas
                                LastName = Korchev

Grid:                    column: FirstName
                            column: LastName

ClientEvents        column: CarType
                            column: Engine

So when i run the application I see in my Grid Column1: Atanas  Column2: Korchev

.ClientEvents(events => events.OnDetailViewExpand(

 

"onDetailViewExpand"))

 

    function onDetailViewExpand(e){
var test  = e.masterRow
test1 = masterRow.cells[0].innerHTML = Atanas
test2 = masterRow.cells[1].innerHTML = Korchev
}

The ID is not in masterRow because it's not in a grid column, this while I fill it in my model
I can read the ID by doing:

var

 

 

grid = $('#mygrid').data('tGrid');

 

 

 

 

var gridData = grid.data;
var ID = gridData[0].ID = 1
var name = gridData[0].FirstName = Atanas

 

So when I have multiple items in my Grid I have to itterate throught it and compare

 

 

for (var i = 0; i < (gridData.length); i++) {
    var name = gridData[i].FirstName 

    if( name = = test1 ){
    var myID = gridData[0].ID
    break;

    }
}
This is how I do it now
Now I have my ID and can go further.

Regards,
Gerard

0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 02:54 PM
Hi Gerard Eikelboom,

 I tried the following in your application and it worked:

function onDetailViewExpand(e) {
            var grid = $('#VoorraadGrid').data('tGrid');
            var tr = $('#VoorraadGrid .t-grid-content tbody tr:first');
            
            var dataItem = grid.dataItem(e.masterRow);
            alert(dataItem);
        }

This is what I meant by using the masterRow. As you can see you can retrieve the dataItem to which the row is bound and use all properties.

All the best,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 25 Mar 2011, 03:08 PM
And the master has spoken.

So easy
Works like a charm.

thank you very much.

Regards,
Gerard
0
Varun
Top achievements
Rank 1
answered on 10 Mar 2012, 12:16 AM
I am using Q1 2012 and this method is not working. I get undefined
 
DetailViewExpanded: function (e) {
       var grid = $('#HistoryGrid').data("tGrid");
       var dataItem = grid.dataItem(e.masterRow);
       alert(dataItem);
        
   }
0
Varun
Top achievements
Rank 1
answered on 13 Mar 2012, 03:43 AM
Sorry about it.. It does work. 
Tags
Grid
Asked by
Gerard Eikelboom
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gerard Eikelboom
Top achievements
Rank 1
Varun
Top achievements
Rank 1
Share this question
or