All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
  Print view

DataEntryGrid, hide rows without filtering the query
Author Message
PostPosted: Fri Jan 31, 2014 3:21 pm 
Offline

Joined: Wed Mar 09, 2011 4:11 pm
Posts: 285
Here is a weird question:
I would like to filter the data in the grid without filtering the query.

For some reason, I have to gather data that must be updated by script (looping through the datasource) but not all data should appear in the grid (but must be present in the data source to be updated).
Is there a way to do that?

Thanks,
takitetontac


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Fri Jan 31, 2014 3:33 pm 
Offline

Joined: Wed Mar 09, 2011 4:11 pm
Posts: 285
There's no out-of-the-box method to do what you are asking, but we can use a js script to find rows from the datasource, then the grid, based on certain criteria and finally hide them from viewing.

For example, my grid, called myDataEntryGrid, has a true/false column with a checkbox called MyChkBox. I would like to hide every row where the checkbox is marked true. To do this, I would use the following code in the DataEntryGrid's LoadCompletedScript, since we want the items to be placed inside the grid, before hiding them:

Code:
var grid = form.GetControl("myDataEntryGrid").InputControl;
var element = grid.CTRL_GRID;
var grd = $(element).data("kendoGrid");

var grdDatasource = grd.dataSource;

for (var i = 0; i < grdDatasource._data.length; i++) {
    if (grdDatasource._data[i].MyChkBox == "1") {
        var row = grd.tbody.find("tr[data-uid='" + grdDatasource._data[i].uid + "']");
        if (row != undefined) {
            row.hide();
        }
    }
}


The basic idea is that, every record in the datasource has a unique UID, which is the same as the grid's row. To find and hide a row in the grid, we would first find it in the datasource, using whatever filters we may need, and then find the corresponding grid row and hide it.

With regards,
Dimitris


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Tue Feb 04, 2014 7:02 pm 
Offline

Joined: Thu Dec 05, 2013 11:29 pm
Posts: 76
Hi Dimitris,

Your point is interesting, but I found another way, using the Kendo grid methods that allow me to group, sort, filter the data dynamically (in the loadCompletedScript for my DataEntryGrid), but I was wondering if there is a way to access the configuration of the grid before it is created, because Methods offer some dynamic possibilities, but accessing the configuration would allow me to get the grid exactly how I want (With grouping, sorting, aggregates...).

Here is an example of what I would like to do with my DataEntryGrid (only for grouping and aggregates possibilities such as editing the headertemplate for the groups and adding totals by group for one field):
http://demos.telerik.com/kendo-ui/web/grid/aggregates.html

Thanks again for your help!


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Thu Feb 13, 2014 5:04 pm 
Offline

Joined: Thu Dec 05, 2013 11:29 pm
Posts: 76
Hello?
Have I been forgotten?


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Wed Feb 19, 2014 12:10 pm 
Offline

Joined: Wed Mar 09, 2011 4:11 pm
Posts: 285
Hello,

I apologize for the delay, it has been a very busy week. You cannot change any paramaters used in the initialization of a grid, but you can perform changes to a grid object's existing parameters. For example:

Code:
var kendoGrid = $(form.GetControl("c_Grid").InputControl.CTRL_GRID).data("kendoGrid");
kendoGrid.hideColumn("FieldName1");
kendoGrid.hideColumn("FieldName2");


You can also use:
Code:
alert(pf.ObjectProperties(kendoGrid));


This should present you with a visualization of a grid object's parameters.

Perhaps we can assist further with what you are trying to do, if you provide us with more details concerning your grouping/sorting requirements.

With regards,
Dimitris


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Wed Feb 19, 2014 6:41 pm 
Offline

Joined: Thu Dec 05, 2013 11:29 pm
Posts: 76
Hi Dimitris,

I had found the methods that allow me to group, sort, hide....
What I would like to do is Group my data by a lookup field and being able to display a total value for each group like in the example in my previous post.

The problem is that I would like to edit the group headers to be able not to display the ID of the lookup value.
I've been able to do that in the LoadCompletedScript of the grid via jQuery, but I have to do it each time the grid is changed (e.g. column filtered), I was wondering if it was possible to do that a cleaner way...

for the totals, I've not been able to find a satisfying solution...

Thanks for your help


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Fri Feb 21, 2014 6:17 pm 
Offline

Joined: Tue Mar 08, 2011 7:37 pm
Posts: 275
hi takitetontac,

You can place this code into includes section of the form. This function can be called in LoadCompletedScript or any button click/value change in order to group the results by a single column, for example:
Code:
GroupGrid(form, "c_Grid");


This is the function that goes into the includes:
Code:
<script>
function GroupGrid(MyForm, GridControlName)
{
   var frm = MyForm;   
   var gridInputControl = frm.GetControl(GridControlName).InputControl;
   var element = gridInputControl.CTRL_GRID;
   var grd = $(element).data("kendoGrid");

   grd.dataSource.group({ field: "FieldNameToGroupBy" ,
      aggregates: [{field:"FieldName1", aggregate: "sum"}, {field:"FieldName2", aggregate:"count"}]});
      
   grd.dataSource.sort({field: "SortingFieldName", dir: "asc"});
}

</script>


Let me know if I'm missing anything

_________________
Spyros Moschovakos

Best Practice Consulting,
http://www.bpc-components.com


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Tue Feb 25, 2014 11:56 pm 
Offline

Joined: Thu Dec 05, 2013 11:29 pm
Posts: 76
Hi Dimitris,

I had already tested this solution, but it doesn't work for me, the grouping and sorting are fine, but not the aggregates...
Did you test this on your side?

Thanks


Top
 Profile  
 

Re: DataEntryGrid, hide rows without filtering the query
PostPosted: Fri Jun 05, 2015 12:35 am 
Offline

Joined: Tue Sep 16, 2014 7:23 pm
Posts: 3
You have to override the default with your own groupHeaderTemplate for the column. This is pretty brute force but you could add to the above . . .

Code:
grd.columns[IndexOfDesiredField].groupHeaderTemplate = "#= value# (#count= count#)"


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Style by custom web design , optymalizacja pozycjonowanie strony pozycjonowanie
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group