Hi,
I have Winform app with SfDataGrid for displaying list of record. I have logic for filtering which works with no issues at all.
I followed the instructions in this site to implement pagination. But the filtering has introduced strange behaviour; when I comment out filtering logic, pagination works fine. These are issues.
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text != "Search...")
{
FilterText = textBox2.Text;
OnFilterChanged();
}
}
private void OnFilterChanged()
{
if (sfDataGrid1.View != null)
{
sfDataGrid1.View.Filter = FilerRecords;
sfDataGrid1.View.RefreshFilter();
}
}
public bool FilerRecords(object o)
{
double res;
bool checkNumeric = double.TryParse(FilterText, out res);
var item = o as ProductListView;
if (item != null && FilterText.Equals(""))
{
return true;
}
else
{
if (item != null)
{
if (item.ProductCode.ToLower().Contains(FilterText) ||
item.ProductName.ToLower().Contains(FilterText.ToLower()) ||
item.ItemType.ToLower().Contains(FilterText.ToLower()) ||
item.Category.ToLower().Contains(FilterText.ToLower()) ||
item.UnitOfSale.ToLower().Contains(FilterText.ToLower()) ||
item.Location.ToLower().Contains(FilterText.ToLower()) ||
item.UnitsInStock.ToString().Contains(FilterText.ToLower()) ||
item.SalesPrice.ToString().Contains(FilterText.ToLower()) ||
item.QuantityPerUnit.ToString().Contains(FilterText.ToLower()) ||
item.FreeStock.ToString().Contains(FilterText.ToLower()) ||
item.QuantityAllocated.ToString().Contains(FilterText.ToLower()))
return true;
return false;
}
}
return false;
}
Thanks in advance for usual assistance
Regards,
Paul Aziz
Hi Paul,
We have reviewed the reported scenario and understand that you are using SfDataPager with SfDataGrid and applying filtering logic. We would like to clarify the behavior of the filtering with pagination. For example, if there are 4 pages and you are on page 3, when you enter text in the search box, the filter will apply to all records across all pages. If the page size is 3 and the filtered result contains 4 records, then the first page will display 3 filtered records and the second page will display 1 filtered record. The focus will remain in first page to show the filtered records from the beginning. This is the expected behavior and not an issue.
Kindly share your expected filtering requirement with pagination. Please confirm, if you need to filtering apply only to the current page while keeping other pages unchanged?
We have also checked the behavior of the last button of SfDataPager in the current version(v31.2.12) and the button works as expected.
To investigate further, please share the following details.
This information will help us investigate further and provide an accurate solution.
Find the sample demo in the attachment.
Regards,
Rabina M
Hi Rabina,
Thanks so much for the reply.
Regards,
Paul A
Paul,
We hope that we have clarified your requirement. Please get back to us if you need any further assistance; we will be happy to help you.
Hello Rabina M,
Thanks so much for the assistance. I am indeed grateful.
Paul,
Thanks for the update, we will wait until we hear from you.
I’m still encountering some quirks pagination and filtering. I have upgraded to version 30.1.37 and my target framework: .NET Framework 4.8
Issue Description:
To make this clearer, I’ve attached a short screen recording demonstrating the issue step by step.
Thanks for your usual assistance
Best regards,
Paul A
Paul,
We have investigated the reported scenario and reviewed the video you shared. In the video with filtering, when you click the last button, the page does not navigate, and the button appears disabled. However, after navigating to other pages, the last button works. It seems that the filter was not applied by entering text in the search box. To verify this, we applied the filter during the initial load and tested the last button behavior, and it worked as expected.
To investigate further, please share the following details.
Find the sample demo in the attachment.
This information will help us investigate further and provide an accurate solution.
Hi Raina,
Thanks for the reply. Find my filtering logic below:
private void textBox2_TextChanged_1(object sender, EventArgs e)
{
var textBox = sender as System.Windows.Forms.TextBox;
if (textBox.Text != "Search...")
{
FilterText = textBox.Text;
OnFilterChanged();
textBox2.Focus();
}
}
private void OnFilterChanged()
{
if (sfDataGrid1.View != null)
{
sfDataGrid1.View.Filter = FilerRecords;
sfDataGrid1.View.RefreshFilter();
}
}
public bool FilerRecords(object o)
{
var item = o as ProductListView;
if (item != null && string.IsNullOrEmpty(FilterText))
{
return true;
}
else if (item != null)
{
if (item.ProductCode.ToString().Contains(FilterText) ||
item.ProductName.ToLower().Contains(FilterText.ToLower()) ||
item.ItemType.ToLower().Contains(FilterText.ToLower()) ||
item.Barcode.ToLower().Contains(FilterText.ToLower()) ||
item.Location.ToString().Contains(FilterText))
{
return true;
}
return false;
}
return false;
}
2. Are there any customizations required to replicate the scenario?
I don't require any customization, I just want records paginated and filterable.
3. Kindly replicate the issue in the attached sample and share it with us
I have replicated the attached sample in my project, but I get the same inconsistent behavior. I am however, still investigating the to Identify what the problem is.
Thank you for your usual assistance. I am very grateful.
Regards,
Paul Aziz
Paul,
We have reviewed the code you provided and there is no issue with that. In your last update, you mentioned as last page button does not work correctly when filtering is applied, but in your provided video reference (with-filtering video file), we couldn't find that filtering action. So that we request about how you are applying the filter (either on-loading or through text box).
Based on your code, filtering is triggered in the TextChanged event of the textbox, which means filtering occurs only when text is entered. We have tested by applying the filter programmatically and also entering the text in the TextBox, but we unable to replicate the issue at our end.
Please refer to the below video for our test results.
To investigate further, please share the following details:
Without reproducing the issue, we cannot provide an accurate solution. So kindly replicate the issue in our sample and share it back with us.
Find the sample demo in the attachment.
This information will help us investigate further and provide an accurate solution.
Hello Rabina,
Thanks for your patience and assistance.
The culprit was this line of code below in the Form_Shown event: textBox2.Text = "Search...";
I am indeed grateful to you.
Best reagrds,
Paul
Paul,
We
glad that the query was addressed from your side. If you have any other
queries, please create a new forum. Hence, we are closing this forum.