access list of filtered items in dataview - slickgrid

I'm using a DataView to populate the Grid, and using filters to interact with the visible rows. My problem is after applying the filters, on rows change, or rows count change... how can I access the dataview to iterate over only those visible rows, to do some calculations for example?
Because rows themselves are not publicly exposed... and if they were, a row is not always a data element, since can also refer to a Group, right?
Is there an easy way to access those filtered data elements then?
(I guess what I'm looking for is something like being able to access "var filteredItems = getFilteredAndPagedItems(_items, _filter);")
thanks,

Use dataView.getLength() and dataView.getItem(index) to access filtered/paged/grouped data.
This is the interface the grid is using to talk to the data source.

I posted a solution here if you want to give that a look. Also for those who might be looking for something similar.
Get Filtered data from Dataview in Slickgrid
if you want to show the information that's being filtered and whats on the current page you can do something like this.
var pagingInfo = dataView.getPagingInfo();
var start = pagingInfo['pageSize'] * (pagingInfo['pageNum']);
var filteredAndPagedItems = dataView.getFilteredItems().slice(start,(start + pagingInfo['pageSize']));
console.table(filteredAndPagedItems);
something along those lines.the getFilteredItems is a custom function i added to the dataview.js. for more information view the link.

Related

tabulator filter: ungroup filter results

in my tabulator table I group specific rows. When I load the page I keep the groupings closed, so that the user can open those grouping he is interested in. (see attached screenshot)
But I would like to automatically open the groupings, when the user applies a filter to any column of the table. (because in this case I want him to see the results on first glance and I do not want him to open the grouping manually) Do you know how I can set up this specific requirement?
Open grouping when applying a column filter in tabulator js
Thank you very much in advance.
Best regards
To check when the table is filtered you can use the dataFiltered callback, you would need to check through the filters passed into the callback to make sure that there are filters actually applied before carrying out your app logic.
var table = new Tabulator("#example-table", {
dataFiltered:function(filters, rows){
//filters - array of filters currently applied
//rows - array of row components that pass the filters
},
});
You could the use the getGroups function to return an array of the Group Components for the table, and the itterate through the list and open the groups using the show function:
table.getGroups().forEach(function(group){
group.show();
});
I hope that helps,
Cheers
Oli :)

jsGrid - get data typed by the user in a search navGrid

I'm trying to bind a table and a graph using d3 and jqGrid library. For that I have to get the search typed by the user in the searchbox (my table looks like this : http://www.guriddo.net/demo/guriddojs/)
I've found this function :
grid.getGridParam("postData").filters
but I don't know how to use it. I thought about the trigger event "jqGridToolbarAfterSearch" to get the data after each search but doesn't seems to work...
If someone has an idea I'll be very grateful!
Thanks.
Ps : if the same method exist to set data, I'm interested too.
I hope that I correctly understand your problem. I suppose that you first converts the CSV data of the demo to some more continent data format: array of items with some properties (name, economy, cylinders, displacement, power, weight, mph, year). Then you can use datatype: "local" and data as the input data. I suppose that the user apply the local filter and then you want to get the filtered data
If you use free jqGrid fork of jqGrid (it's the fork which I develop) then you can get lastSelectedData parameter (var filteredData = $grid.jqGrid("getGridParam", "lastSelectedData");) to have the array of filtered items (see the demo). After that you can use d3 with the filtered items.

How can I get the IQueryable object used by LinqDataSource?

Is there a way to get the IQueryable object that the LinqDataSource has used to retrieve data? I thought that it might be possible from the selected event, but it doesn't appear to be.
Each row in my table has a category field, and I want to determine how many rows there are per category in the results.
I should also note that I'm using a DataPager, so not all of the rows are being returned. That's why I want to get the IQueryable, so that I can do something like
int count = query.Where(i => i.Category == "Category1").Count();
Use the QueryCreated event. QueryCreatedEventArgs has a Query property that contains the IQueryable.
The event is raised after the original LINQ query is created, and contains the query expression before to it is sent to the database, without the ordering and paging parameters.
There's no "Selected" event in IQueryable. Furthermore, if you're filtering your data on the server, there'd be no way you can access it, even if the API exposed it, but to answer a part of the question, let's say you have category -> product where each category has many products and you want the count of the products in each category. It'd be a simple LINQ query:
var query = GetListOfCategories();
var categoryCount = query.Select(c => c.Products).Count();
Again, depending on the type of object GetListOfCategories return, you might end up having correct value for all the entries, or just the ones that are loaded and are in memory, but that's the different between Linq-to-Objects (in memory) and Linq-to-other data sources (lazy loaded).

Date Ranges in jqGrid Searches

We are using advanced search in the latest version of jqGrid, and our search dialog is configured to be always visible on the page above the grid. The structure of our data lists is dynamic. Thus, when we are going to display a list, we first do an ajax call to get the list of columns for the grid. We then construct the data model for the grid and make a request for the data.
Currently, in the request to get the columns, we return the data type of the column. If the data is a date, we display a date picker in the search form. However, some of our customers HATE having to use <= >= for date ranges. They want to be able to pick a date column and then set a start and end date using two side-by-side date pickers. I've been pushing them off for a while now because they have the ability to do date range searches, but the complaining isn't stopping. (It's more clicks to add the second filter with the end date)
Is there any way I can modify jqGrid to give me a date range control when I am configuring a search on a date column? I really don't want to have to set up an external search dialog UI just to deal with these complaints, but product-management is pushing really hard to get "normal" date ranges for the grids.
You can create your own custom search dialog. See this question which I asked couple days ago.
using setGridParam to change your postData array and include extra values in the filters JSON object that will be carried over to your server side where you can dissect it. In your case you can pass over your data range Start and End inside the filter item of the postData. Then reload your jqGrid like this
var $grid = $("#list');
//$grid.setGridParam({datatype:'json', page:1}).trigger('reloadGrid');
var post_data = {searchField:'',searchString:'', searchOper:'',
filters:'{"groupOp":"OR","rules":['+
'{"field":"Date","op":"ge","data":"2012-04-23"},'+
'{"field":"Date","op":"lt","data":"2012-04-25"}' +
']}'
};
$grid.setGridParam({postData:post_data}).trigger('reloadGrid');
The above will save the postData array with the new config and the reloadGrid sends a request to the server with the new postData array. This will preserve the paging as well; however, to get the old view of your grid (without search terms) you need to implement the reset button separately too and trigger reloadGrid after that for this to take effect.
Not sure if you have solved your problem by now; however, I am putting this solution here for any one from the future who has the same issue.
As far I know there is no way to do this, but to write it yourself.
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_searching
Filter jqGrid Data by Date Range?

Ultragrid : how to best add a set of sub rows programatically?

I have an Infragistics Ultragrid that is being used to display a list of attributes. Sometimes the attribute is an array so I am adding a sub row for each element so the user can optionally expand the row showing the array attribute and see all the element values.
So for each element I use:
var addedRow = mGrid.DisplayLayout.Bands[1].AddNew();
which if I have 300 elements gets called 300 times and takes around 9 seconds (I have profiled the application and this call is taking 98% of the elapsed time)
Is there a way to add these sub rows more efficiently?
I know I'm late with an answer, but hopefully someone can use my answer anyway. Whenever I need to set rows and subrows for ultragrid, I simply set the datasource by using linq and anonymous types to generate the propper collection.
say you have a list of persons (id, Name), and a list of cars (id, CarName, and OwnerId (personId))
now you like to show a gridview showing all persons, with an expandabel subrow providing which cars they own. simply do the following.
List<Person> persons = GetAllPersons();
List<Car> cars = GetAllCars();
grid.DataSource = persons.Select(x => new {x.Id, x.Name, Cars = cars.Where(z => z.OwnerId == x.Id).ToList()}).ToList();
Note the anonymous type I make, this will generate a list of objects having an id, Name, and a collection of cars. Also note that I call the ToList method twice in the last line, this is necessary in order to get ultragrid to bind properly.
Note further more that if you need to edit the gridview, the above method migth not be sufficient, as the ultragrid needs an underlaying datasource for modifying, and I dont believe that this will cope. BUT on the internet you'll find some extensions that can copy a Linq collection into a DataTable, doing that and then you should also be able of editing the grid.
I have often used the above method and it performs extremely well, even for huge collections.
Hope this helps somebody
you might want to use ultraGrid1.BeginUpdate(); and ultraGrid1.EndUpdate(true); to stop screen from repainting. made huge performance benefit for my app.
Also in my case I was populating nearly >10,000 rows, so have used UltraDataSource

Resources