Looping through a Filtered Grid in a Dashboard

Hello All,

I’m working with the grid in a dashboard. The user has the ability to filter the grid. I’m able to loop through the entire resultset, but is there a way to only get the filtered records within the grid?

EpiDataView edv_KitPullingSchedule;
edv_KitPullingSchedule = (EpiDataView)oTrans.EpiDataViews["V_KitPullingSchedule_1View"];
	
foreach (DataRowView edv_ScheduleRow in edv_KitPullingSchedule.dataView)  //Loop thru each record in the grid

So the easy way is to do no programming. Right click in grid and select Show Grid Filters and then let the user filter it the way they need to. Which you may be doing already “The user has the ability to filter the grid.”

To do it using code as you loop through the data view, add the row that meets your criteria to a new data table (or dataset with a new data table inside it) and then after the loop bind that data table to the grid’s data source. I have done this with datasets being returned from a dynamic query and before assigning as the data source. I also have looped through a grid after it has been populated and re-assigned the new data source to the grid. It just depends on what the user needs to see on the grid and when. But I have never done it on a data view but it should work the same.

If no rows meet the criteria set the data source to null and it will clear the grid.

Scott

/opcode is the column name u want to set filter and there respective value/
string rowFilter = "OpCode = ‘UTAUTO’ or OpCode = ‘UTMAN’ or OpCode = ‘BALANCE’ ";

        edv_KitPullingSchedule.dataView.RowFilter = rowFilter;
        if (edv_KitPullingSchedule.dataView.ToTable().Rows.Count > 0)
        {
            foreach (DataRow dr in edv_KitPullingSchedule.dataView.ToTable().Rows)
            {
                MessageBox.Show("From Epicor Dataview " + dr["OpCode"].ToString());
            }
        }

        else
        {
            EpiMessageBox.Show("No Data after filter");
        }

// edvJobOper.dataView.RowFilter = string.Empty; /* remove rowfilter */

I don’t think @DurangoBurke wants to set the filter through code. I think the user will have already filtered the grid and he wants to loop through the filtered records instead of the complete grid dataset.

@DurangoBurke you need to get a hold of the grid using the csm.GetNativeControlReference(“Guid”); instead of using the data view, the filter on the grid is filtering the Grid View not the Data View itself.
Try this

EpiUltraGrid ug = (EpiUltraGrid)csm.GetNativeControlReference("MY_GUID_FROM_THE_GRID");
UltraGridRows[] filteredRows = ug.Rows.GetFilteredInNonGroupByRows();
for( int i=0; i < filteredRows.Length;i++)
{
          ug.Rows[filteredRows[i].Index].Cells["MyColumn"].Value...... /*etc*/
}

References

1 Like