Why RadFilter is not detecting Columns correctly? - filter

I am having trouble that RadFilter is not detecting the columns correctly. I bind my RadGrid through code in Asp like:
RadGrid1.DataSource = myDataSource;
RadGrid.DataBind();
RadFilter is only binding those columns which are bind through and ignoring those who are in . Is this a known issue? as I didn't see any thread talking about this problem. Waiting for help immediately.
Regards,
Wasim.

If I am understanding you correctly, you need to add FilterFieldEditors to the RadFilter for any field that is not represented in the DataSource for the grid.
You can add filters dynamically with the following code.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
var fieldName = "myDynamicFilterField";
var friendlyName = "Friendly Dynamic Field";
var newTextFieldEditor = new RadFilterTextFieldEditor();
filter.FieldEditors.Add(newTextFieldEditor);
newTextFieldEditor.FieldName = fieldName; // name filter will used for filter exressions
newTextFieldEditor.DisplayName = friendlyName; // name use will see when they selected a field to filter
// ** Repeat for all dynamic fields **
}
}
I was able to get a working version using auto generated columns and custom added columns, but ran into many other problems. I ended up just dynamically creating all the filter fields (as shown above) from the data source and applying the filter expression to the grid.

Related

Oracle ADF LOVs value binding to multiple text fileds

I have a use case where I have created a view object that contains 3 values namely LOC_CODE, LOC_DESC, CITY_DESC. Now in my ADF form I would like to display all 3 values in such a way so that user would have a provision to select LOC_CODE From Popup(LOV) and rest two fileds LOC_DESC & CITY_DESC should be changed accordingly. Currently the popup shows all 3 values but when I select the row and click on OK button it only fills the LOC_CODE in 1 textbox.
Below is the scenario of the same:
Got the solution. Just need to add a textbox or drag and drop near respective field and bind it with required binding object. For e.g. in this case LOC_DESC & CITY_DESC is available in my data control as DefLoc & DefCity that contains SQL to fetch respective description value. Now I need to drag and drop DefLoc & DefCity and binding is automatically done or just check binding in value.
you have to add valuechangelistener to location code. set autosubmit true.
now in backing bean use following code:
public void valuechangelistener(ValueChangeEvent valueChangeEvent) {
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlListBinding list = (JUCtrlListBinding)bindings.get("LOC_CODE");
String selectedValue = (String)list.getAttributeValue();
list.getListIterBinding().setCurrentRowWithKeyValue(selectedValue);
Row currRow = list.getListIterBinding().getCurrentRow();
if (currRow != null) {
bndloc_desc.setValue(currRow.getAttribute("LOC_DESC"));
bndcity_desc.setValue(currRow.getAttribute("CITY_DESC"));
}
}
now set partial trigger to both location desc and city desc with id of LOC_CODE.
After doing this you will get your desired result.
update after implementing it.
In my case JDeveloper 12.2.1.3.0
public void valueChangeListener(ValueChangeEvent valueChangeEvent) {
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlListBinding list = (JUCtrlListBinding) bindings.get("YourBindingforLOV");
String selectedValue = (String) valueChangeEvent.getNewValue();
list.getListIterBinding().setCurrentRowWithKeyValue(selectedValue);
Row currRow = list.getListIterBinding().getCurrentRow();
if (currRow != null) {
String s = (String) currRow.getAttribute("YourAttributeName");
}
}

Sorting DataTable bound to DataGrid with custom datatypes

I have a DataTable where all column datatypes are of a custom class called CellModel.
The table's defaultview is bound to a DataGrid, which autogenerates some templatecolumns where I setup DataTemplates and Bindings, and showing the data works perfect.
My issue is when i try to sort on the columns.
I want to sort on a specific property within the custom class, but the default sorter won't recognize the custom class, so it invokes ToString() instead. By overriding and returning my property i'm able to sort, but it is PAINFULLY slow.
I've tried to implement a custom sorter on DataGrid.Sorting event like this:
private void DG_Sorting(object sender, DataGridSortingEventArgs e)
{
var column = e.Column;
e.Handled = true;
var direction = (column.SortDirection != ListSortDirection.Ascending)
? ListSortDirection.Ascending
: ListSortDirection.Descending;
var lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(DG.ItemsSource);
column.SortDirection = direction;
lcv.CustomSort = new MyComparer();
lcv.Refresh();
}
But GetDefaultView returns BindingListCollectionView which don't support CustomSorters..
I'm lost. How do I implement a custom comparer for sorting the data?
Found the issue. by using the lcv.SortDescriptions and implementing the IComparer interface on the CellModel class, i was able to use custom comparison.
Also, the sorting speed was influenced since i had Virtualization disabled on the Datagrid. by enabling Virtualization, the sorting was faster.

Access Data Source Fields from Report code behind

I want to programmatically access the Fields collection in the ObjectDataSource object of my Telerik report.
I did notice in the design portion of the Telerik report you can access the fields collection
in the Value by using the Edit Expression window.
Example:
= Fields.MyFieldName
How would I accomplish this task using C# code in the report code behind file?
I had the same problem. This is how I solved it, although I believe there should be an easier way.
First I created a method for the details section itemdatabinding:
private void detail_ItemDataBinding(object sender, EventArgs e)
{
Telerik.Reporting.Processing.DetailSection section = (sender as Telerik.Reporting.Processing.DetailSection);
object id = section.DataObject["Data Field You want to access"];
Variable Name = id.ToString();
}
You can now use that variable anywhere in your codebehind.
Note: The Data Field must appear in your detail section. In my case I did not need it to show, so I just made 'Visible=false'.
This worked for me.
Bind Data to your own data to your variables
string ItemCode = "a";
string ItemDesc = "aa"
Then bind it to the data source
var Output = new
{
ItemCode = a.ItemCode,
ItemDesc = a.ItemDesc,
};
this.DataSource = Output;
All these are in code behind. Then move to design portion and modify your text-box as shown below.
= Fields.ItemCode
= Fields.ItemDesc

Exporting a filtered Grid data In Telerik RadGrid

When exporting a rad grid data if the user has it filtered in any way the grid should just export the filtered data not the entire dataset - Any idea how to achieve this?
Regards - Hemant
Here is a solution that allows one to get a filtered, sorted list of data items using the current filter and sort settings from a Telerik RadGridView control (Silverlight version).
using Telerik.Windows.Data;
.
.
.
IEnumerable<MyClass> itemsToDisplay { get; set; } //The RadGridView is bound to this property
public void DoSomethingWithFilteredAndSortedDisplayItems(RadGridView rgv)
{
IQueryable<MyClass> iqItems = itemsToDisplay.AsQueryable();
FilterDescriptorCollection filter = rgv.FilterDescriptors;
SortDescriptorCollection sort = rgv.SortDescriptors;
List<MyClass> fsItems = iqItems.Where(filter).Sort(sort).ToIList() as List<MyClass>;
if (fsItems != null && fsItems.Count > 0)
{
DoSomethingWithDisplayItems(fsItems);
}
}
public void DoSomethingWithDisplayItems(IEnumerable<MyClass> list)
{
... //Do something
}
I think that if you assign the filtered set of data to the grid before calling the export method (which internally rebinds it), you will get the filtered values in the exported file.

Using DataObjectTypeName in DataObjectSource

The functionality I am trying to use is:
- Create a ObjectDataSource for selection and updating controls on a web page (User Control).
- Use the DataObjectTypeName to have an object created that would send the data to an UpdateMethod.
- Before the values are populated in the DataObjectTypeName’s object, I would like to pre-populate the object so the unused items in the class are not defaulted to zeros and empty strings without me knowing whether the zero or default string was set by the user or by the application.
I cannot find a way to pre-populate the values (this was an issue back in 2006 with framework 2.0). One might ask “Why would anyone need to pre-populate the object?”. The simple answer is: I want to be able to randomly place controls on different User Controls and not have to be concerned with which UpdateMethod needs to handle which fields of an object.
For Example, let’s say I have a class (that reflects a SQL Table) that includes the fields: FirstName, LastName, Address, City, State, Zip. I may want to give the user the option to change the FirstName and LastName and not even see the Address, City, State, Zip (or vice-versa). I do not want to create two UpdateMethods where one handled FirstName and LastName and the other method handles the other fields. I am working with a Class of some 40+ columns from multiple tables and I may want some fields on one screen and not another and decide later to change those fields from one screen to another (which breaks my UpdateMethods without me knowing).
I hope I explained my issue well enough.
Thanks
This is hardly a solution to the problem, but it's my best stab at it.
I have a GridView with its DataSourceID set to an ObjectDataSource.
Whenever a row is updated, I want the property values in the object to be selectively updated - that is - only updated if they appear as columns in the GridView.
I've created the following extension:
public static class GridViewExtensions
{
public static void EnableLimitUpdateToGridViewColumns(this GridView gridView)
{
_gridView = gridView;
if (_gridView.DataSourceObject != null)
{
((ObjectDataSource)_gridView.DataSourceObject)
.Updating += new ObjectDataSourceMethodEventHandler(objectDataSource_Updating);
}
}
private static GridView _gridView;
private static void objectDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
var newObject = ((object)e.InputParameters[0]);
var oldObjects = ((ObjectDataSource)_gridView.DataSourceObject).Select().Cast<object>();
Type type = oldObjects.First().GetType();
object oldObject = null;
foreach (var obj in oldObjects)
{
if (type.GetProperty(_gridView.DataKeyNames.First()).GetValue(obj, null).ToString() ==
type.GetProperty(_gridView.DataKeyNames.First()).GetValue(newObject, null).ToString())
{
oldObject = obj;
break;
}
}
if (oldObject == null) return;
var dynamicColumns = _gridView.Columns.OfType<DynamicField>();
foreach (var property in type.GetProperties())
{
if (dynamicColumns.Where(c => c.DataField == property.Name).Count() == 0)
{
property.SetValue(newObject, property.GetValue(oldObject, null), null);
}
}
}
}
And in the Page_Init event of my page, I apply it to the GridView, like so:
protected void Page_Init()
{
GridView1.EnableLimitUpdateToGridViewColumns();
}
This is working well for me at the moment.
You could probably apply similar logic to other controls, e.g. ListView or DetailsView.
I'm currently scratching my head to think of a way this can be done in a rendering-agnostic manner - i.e. without having to know about the rendering control being used.
I hope this ends up as a normal feature of the GridView or ObjectDataSource control rather than having to hack it.

Resources