VS
Vijayarasan Sivanandham
Syncfusion Team
May 11, 2020 06:22 PM UTC
Hi Khanh Dang,
Thank you for contacting Syncfusion support.
Currently, SfDataGrid does not have a support for Advance Search. We are checking the feasibility to achieve your requirement and we will update you the details on May 13, 2020.
Regards,
Vijayarasan S
VS
Vijayarasan Sivanandham
Syncfusion Team
May 14, 2020 03:49 AM UTC
Hi Khanh Dang,
Sorry for the inconvenience caused.
We are currently working on this and we need two more business days to validate this. We will update you with further details on May 15, 2020.
We appreciate your patience until then.
Regards,
Vijayarasan S
SS
Susmitha Sundar
Syncfusion Team
May 19, 2020 03:20 AM UTC
Hi khanh dang,
Sorry for the inconvenience caused.
We are provided the searching for column wise only. We have achieved your requirement for empty column. Now, we are working for the requirement “Search for empty rows”. We will provide the update on May 19, 2020.
We appreciate your patience until then.
Regards,
Susmitha S
SS
Susmitha Sundar
Syncfusion Team
May 19, 2020 11:46 AM UTC
Hi khanh dang,
Thank you for your patience.
We have achieved your requirement by overriding the SfDataGrid.SearchController and modify the SearchController.FilterRecords method.
|
public class SearchControllerExt : SearchController
{
SearchPanel searchPanel;
public SearchControllerExt(SfDataGrid grid, SearchPanel panel) :
base(grid)
{
searchPanel = panel;
this.AllowHighlightSearchText = false;
}
protected override bool FilterRecords(object dataRow)
{
if (this.Provider == null)
Provider = this.DataGrid.View.GetPropertyAccessProvider();
if (searchPanel.chkEmptyRows.Checked)
{
for (int i = 0; i < this.DataGrid.Columns.Count; i++)
{
var col = this.DataGrid.Columns[i];
var cellvalue = Provider.GetFormattedValue(dataRow, col.MappingName);
if (cellvalue == null)
continue;
else
return false;
}
return true;
}
else if (searchPanel.chkNonEmpty.Checked)
{
for (int i = 0; i < this.DataGrid.Columns.Count; i++)
{
var col = this.DataGrid.Columns[i];
var cellvalue = Provider.GetFormattedValue(dataRow, col.MappingName);
if (cellvalue != null)
continue;
else
return false;
}
return true;
}
else if(searchPanel.chkEmptyCell.Checked)
{
for (int i = 0; i < this.DataGrid.Columns.Count; i++)
{
var col = this.DataGrid.Columns[i];
var cellvalue = Provider.GetFormattedValue(dataRow, col.MappingName);
if (cellvalue == null)
return true;
else
continue;
}
return false;
}
else
return base.FilterRecords(dataRow);
}
} |
Please check the sample and let us know if you need further assistance on this.
Regards,
Susmitha S
TG
The GridLock
May 19, 2020 04:48 PM UTC
Thanks Susmitha, I will try your code soon
VS
Vijayarasan Sivanandham
Syncfusion Team
May 20, 2020 09:24 AM UTC
Hi Khanh Dang,
Thanks for the update.
We will wait to hear from you.
Regards,
Vijayarasan S
TG
The GridLock
June 11, 2020 06:36 PM UTC
Hi ,
I like this approach. Thanks for the support!
VS
Vijayarasan Sivanandham
Syncfusion Team
June 12, 2020 04:46 PM UTC
Hi Khanh Dang,
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
Regards,
Vijayarasan S
TG
The GridLock
June 13, 2020 01:34 PM UTC
Hi Vijayarasan,Do I need to reset the searchcontroller when I no longer use this extension function? How do I give it up?
SS
Susmitha Sundar
Syncfusion Team
June 15, 2020 04:54 PM UTC
Hi khanh dang,
You can achieve the default searching by this same SearchController. In this sample, I have added the text box to search the text,
|
private void btnSearch_Click(object sender, EventArgs e)
{
if(textBox1.Text== string.Empty)
{
sfDataGrid.SearchController.Search(" ");
}
else
{
sfDataGrid.SearchController.Search(textBox1.Text);
}
} |
Please let us know if you need further assistance on this.
Regards,
Susmitha S
TG
The GridLock
June 15, 2020 05:39 PM UTC
Hi Vijayarasan, I mean destroy the class assignment to the searchcontroller.
SS
Susmitha Sundar
Syncfusion Team
June 16, 2020 05:38 PM UTC
Hi khanh dang,
Thank you for the update.
If you don’t want that customized searching behavior, you need to manually remove the SearchController assigning code.
|
public Form1()
{
InitializeComponent();
orderInfo = new OrderInfoCollection();
this.sfDataGrid1.DataSource = orderInfo.OrdersListDetails;
panel = new SearchPanel(this.sfDataGrid1);
sfDataGrid1.Controls.Add(panel);
panel.BringToFront();
panel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
panel.Location = sfDataGrid1.TableControl.PointToClient(new Point(sfDataGrid1.Width - (panel.Width) - 8, 363));
panel.Show();
sfDataGrid1.TableControl.KeyDown += TableControl_KeyDown;
this.sfDataGrid1.SearchController.AllowHighlightSearchText = false;
sfDataGrid1.SearchController = new SearchControllerExt(sfDataGrid1, panel);
} |
Please let us know if you need further assistance on this.
Regards,
Susmitha S
TG
The GridLock
June 16, 2020 08:40 PM UTC
Hi susmitha,Thanks for sample code, I got it.
SS
Susmitha Sundar
Syncfusion Team
June 17, 2020 05:35 AM UTC
Hi khanh dang,
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this.
Regards,
Susmitha S
TG
The GridLock
June 23, 2020 06:23 PM UTC
Hi Susmitha,I have a datagrid, after using the filter function, I want to continue using advance search, can I continue to search based on this filter view? I tried but it searched the entire view, including the filter results. can i use
this but search all column?
SS
Susmitha Sundar
Syncfusion Team
June 25, 2020 02:45 AM UTC
Hi khanh dang,
Thank you for the update.
In SfDataGrid, searching performed on only filtered records. Please refer the below sample. In this sample, we have the records only 10. And it has country name Germany for two rows. I have filtered the one of the rows. When I search Germany, it will show only one match.
Please check the sample and let us know if you need further assistance on this.
Regards,
Susmitha S
TG
The GridLock
June 25, 2020 06:47 AM UTC
Hi susmitha,
agree, searching performed on only filtered records, The steps I have taken are:
step1: run your code
Step2: Filter "Germany" in Column Country
Step3: Search "Martin"
This is what I expected, but the problem I realized is that 'search method' checks all rows in the database [10 rows] containing "Martin" and then matches the rows shown in the filter to get final result. (I used the search override and when I debug, it checked all the rows.)
I want it to be faster (check only filtered rows [3 rows] then search for "Martin" on these 3 rows) to get final result.
VS
Vijayarasan Sivanandham
Syncfusion Team
June 25, 2020 04:44 PM UTC
Hi Khanh Dang,
Thanks for the update.
Currently, we are analyzing your requirement of “Advance Search performance on SfDataGrid”. We will validate and update you the details on June 26, 2020.
We appreciate your patience until then.
Regards,
Vijayarasan S
TG
The GridLock
June 25, 2020 11:18 PM UTC
Hi Vijayarasan,New question: I can change cell values by 2 ways: using setvalue and manual edit.
Please show me how to cancel value_change if it has a value other than "Abc" for both ways.
VS
Vijayarasan Sivanandham
Syncfusion Team
June 26, 2020 04:15 PM UTC
Hi Khanh Dang ,
Thanks for the update.
Please find answer for your queries below
|
Queries |
Solutions |
|
the problem I realized is that 'search method' checks all rows in the database [10 rows] containing "Martin" and then matches the rows shown in the filter to get final result
|
Currently, we are analyzing your requirement of “Advance Search performance on SfDataGrid”. We will validate and update you the details on June 30, 2020.
|
|
I can change cell values by 2 ways: using setvalue and manual edit.
Please show me how to cancel value_change if it has a value other than "Abc" for both ways.
|
Manual Edit:
Your requirement can be achieved by using SfDataGrid.CurrentCellValidating event. Please refer the below code snippet,
|
sfDataGrid.CurrentCellValidating += SfDataGrid_CurrentCellValidating;
private void SfDataGrid_CurrentCellValidating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellValidatingEventArgs e)
{
if (e.NewValue.ToString() != "Abc")
e.NewValue = e.OldValue;
} |
SetValue:
In this case you need to set the condition before the Set value. Because we set value in programmatic to add the value in SfDataGrid. If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further.
|
Regards,
Vijayarasan S
TG
The GridLock
June 29, 2020 08:19 AM UTC
Hi Vijayarasan,Thanks for the clear explanation.
If i want to delete this record ! can i do this?
sfDataGrid.CurrentCellValidating += SfDataGrid_CurrentCellValidating;
private void SfDataGrid_CurrentCellValidating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellValidatingEventArgs e)
{
if !(conditional1)
e.newvalue=e.oldvalue;
if !(conditional2)
sfDataGrid.deleteselectedrecord();
}
VS
Vijayarasan Sivanandham
Syncfusion Team
June 29, 2020 05:06 PM UTC
Hi Khanh Dang,
Thanks for the update.
In SfDataGrid CurrentCellValidating event fires on Editing in SfDataGrid. So, the selected record could not be deleted when editing in progress. The current cell will not end the editing until the CurrentCell validation is progress. Your requirement Can be achieved by using SfDataGrid.CurrentCellEndEdit event in SfDataGrid. Please refer the Below code snippet,
|
this.sfDataGrid1.CurrentCellEndEdit += SfDataGrid1_CurrentCellEndEdit;
private void SfDataGrid1_CurrentCellEndEdit(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellEndEditEventArgs e)
{
if !(conditional2)
sfDataGrid1.DeleteSelectedRecords();
} |
Regards,
Vijayarasan S
TG
The GridLock
June 30, 2020 07:37 AM UTC
ok Vijayarasan , i got it.
VS
Vijayarasan Sivanandham
Syncfusion Team
June 30, 2020 04:49 PM UTC
Hi Khanh Dang,
Thanks for the update.
Your requirement can be achieved by customization SearchController.FilterReocrds method to search the match text for view records in SfDataGrid. Please refer the below code snippet,
|
public class SearchControllerExt : SearchController
{
SfDataGrid dataGrid;
public SearchControllerExt(SfDataGrid grid) :
base(grid)
{
dataGrid = grid;
}
protected override bool FilterRecords(object dataRow)
{
if (dataGrid.View.Records.Any(x => (x.Data as OrderInfo).OrderID.ToString().Equals((dataRow as OrderInfo).OrderID.ToString())))
return base.FilterRecords(dataRow);
else return false;
}
protected override bool MatchSearchText(GridColumn column, object record)
{
return base.MatchSearchText(column, record);
}
} |
Regards,
Vijayarasan S
TG
The GridLock
June 30, 2020 05:24 PM UTC
Hi Vijayarasan ,After filtering, I have these 3 lines, I want if I continue to search, the code will only check these 3 lines (ID: 7,8,9)
I checked your code, they keep checking from the beginning all the rows.
VS
Vijayarasan Sivanandham
Syncfusion Team
July 1, 2020 06:05 PM UTC
Hi Khanh Dang,
Thanks for the update.
Can you please confirm, In your sample Filtering enable for SfDataGrid and applied UI Filter then Search the text with enabled Searchcontroller.AllowFiltering?
Regards,
Vijayarasan S
TG
The GridLock
July 2, 2020 11:22 AM UTC
VS
Vijayarasan Sivanandham
Syncfusion Team
July 4, 2020 03:25 AM UTC
Hi Khanh Dang,
Thanks for the update.
In SfDataGrid normally filters apply for all records because we are using view filter for Searching in SfDataGrid. So, you could improve the performance by enabling UsePLINQ property in SfDataGrid. In this case SfDataGrid performance improves compared to the previous case. Please refer the below code snippet,
|
this.sfDataGrid1.UsePLINQ = true; |
We hope this helps. Please let us know, if you require further assistance on this.
Regards,
Vijayarasan S
TG
The GridLock
July 6, 2020 05:33 AM UTC
Hi Vijayarasan ,Thanks for the suggestion.
VS
Vijayarasan Sivanandham
Syncfusion Team
July 7, 2020 04:11 PM UTC
Hi Khanh Dang,
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
Regards,
Vijayarasan S