Tree structure in react-admin - admin-on-rest

I want to represent my nested data in tree structure. Is there any way to show nested data in tree view using react-admin?

Although experimental you can have a look on this plugin: https://github.com/marmelab/react-admin/tree/master/packages/ra-tree-ui-materialui
It seems that nested data should be of the same resource (e.g categories and subcategories) and not different ones as someone might wish it supported

No, there isn't. You'll have to create a custom React component for that.

Related

Ember sorting/filter table

I am looking to add a filter/sorter table into the application. I need to choose which column can be sorted - and provide change of class glyphs up/down arrows on the columns. The filter box also needs to be outside of the table.
I tried looking at this example, but there are no glyph class changes on the cols and the filter box is inside the table.
http://crodriguez1a.github.io/ember-sort-filter-table/
I looked at this custom solution, but I couldn't see a way of locking the filter to specific cols.
http://www.jarrodctaylor.com/posts/Filter-And-Sort-Tables-In-Ember/
http://emberjs.jsbin.com/yezonaxu/12/edit?html,css,js,output
what about this one -- http://onechiporenko.github.io/ember-models-table/v.2/docs/classes/Components.ModelsTableRowFiltering.html
but the problem here - is how to create some custom markup depending on the data.
You could sort and filter your rows using computed properties. For sorting you could use sort macro. For filter you should implement your own logic, cause filter and filterBy macros does not support observing a value used to filter the array. Use the sorted and filtered rows to generate a simple HTML table or pass it to a table component of your choice.
If you will take DataTables and wrap it in ember component (custom code would work better that some generalized 3rd-party wrapper), you can achieve a lot. Including filtering by columns. It's a bit hard way, though - DataTables is big and it's API is a bit complicated. That's if you want client-side filtering.
For server-side filtering approach would be different - you render UI for filters using ember's methods, convert user's choices to string and pass that to API (which should be modified to support filtering) when asking for data.

Is there a way to sort a content query by the value of a field programmatically?

I'm working on a portal based on Orchard CMS. We're using Orchard to manage the "normal" content of the site, as well as to model what's essentially data for a small application embedded in it.
We figured that doing it that way is "recommended" for working in Orchard, and that it would save us duplicating a bunch of effort in features that Orchard already provides, mainly generating a good enough admin UI. This is also why we're using fields wherever possible.
However, for said application, the client wants to be able to display the data in the regular UI in a garden-variety datagrid that can be filtered, sorted, and paged.
I first tried to implement this by cobbling together a page with a bunch of form elements for the filtering, above a projection with filters bound to query string parameters. However, I ran into the following issues with this approach:
Filters for numeric fields crash when the value is missing - as would be pretty common to indicate that the given field shouldn't be considered when filtering. (This I could achieve by changing the implementation in the Orchard source, which would however make upgrading trickier later. I'd prefer to keep anything I haven't written untouched.)
It seems the sort order can only be defined in the administration UI, it doesn't seem to support tokens to allow for the field to sort by to be changed when querying.
So I decided to dump that approach and switched to trying to do this with just MVC controllers that access data using IContentQuery. However, there I found out that:
I have no clue how, if at all, it's possible to sort the query based on field values.
Or, for that matter, how / if I can filter.
I did take a look at the code of Orchard.Projections, however, how it handles sorting is pretty inscrutable to me, and there doesn't seem to be a straightforward way to change the sort order for just one query either.
So, is there any way to achieve what I need here with the rest of the setup (which isn't little) unchanged, or am I in a trap here, and I'll have to move every single property I wish to use for sorting / filtering into a content part and code the admin UI myself? (Or do something ludicrous, like create one query for every sortable property and direction.)
EDIT: Another thought I had was having my custom content part duplicate the fields that are displayed in the datagrids into Hibernate-backed properties accessible to query code, and whenever the content item is updated, copy values from these fields into the properties before saving. However, again, I'm not sure if this is feasible, and how I would be able to modify a content item just before it's saved on update.
Right so I have actually done a similar thing here to you. I ended up going down both approaches, creating some custom filters for projections so I could manage filters on the frontend. It turned out pretty cool but in the end projections lacked the raw querying power I needed (I needed to filter and sort based on joins to aggregated tables which I think I decided I didn't know how I could do that in projections, or if its nature of query building would allow it). I then decided to move all my data into a record so I could query and filter it. This felt like the right way to go about it, since if I was building a UI to filter records it made sense those records should be defined in code. However, I was sorting on users where each site had different registration data associated to users and (I think the following is a terrible affliction many Orchard devs suffer from) I wanted to build a reusable, modular system so I wouldn't have to change anything, ever!
Didn't really work out quite like I hoped, but to eventually answer the question in your title: yes, you can query fields. Orchard projections builds an index that it uses for querying fields. You can access these in HQL, get the ids of the content items, then call getmany to get them all. I did this several years ago, and I cant remember much but I do remember having a distinctly unenjoyable time with it haha. So after you have an nhibernate session you can write your hql
select distinct civr.Id
from Orchard.ContentManagement.Records.ContentItemVersionRecord civr
join civ.ContentItemRecord cir
join ci.FieldIndexPartRecord fipr
join fipr.StringFieldIndexRecord sfir
This just shows you how to join to the field indexes. There are a few, for each different data type. This is the string one I'm joining here. They are all basically the same, with a PropertyName and value field. Hql allows you to add conditions to your join so we can use that to join with the relevant field index records. If you have a part called Group attached directly to your content type then it would be like this:
join fipr.StringFieldIndexRecord sfir
with sfir.PropertyName = 'MyContentType.Group.'
where sfir.Value = 'HR'
If your field is attached to a part, replace MyContentType with the name of your part. Hql is pretty awesome, can learn more here: https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html But I dunno, it gave me a headache haha. At least HQL has documentation though, unlike Orchard's query layer. Also can always fall back to pure SQL when HQL wont do what you want, there is an option to write SQL queries from the NHibernate session.
Your other option is to index your content types with lucene (easy if you are using fields) then filter and search by that. I quite liked using that, although sometimes indexes are corrupted, or need to be rebuilt etc. So I've found it dangerous to rely on it for something that populates pages regularly.
And pretty much whatever you do, one query to filter and sort, then another query to getmany on the contentmanager to get the content items is what you should accept is the way to go. Good luck!
You can use indexing and the Orchard Search API for this. Sebastien demoed something similar to what you're trying to achieve at Orchard Harvest recently: https://www.youtube.com/watch?v=7v5qSR4g7E0

Slickgrid tree view

I am new to UI development. I am working on a project which already uses slickgrid for displaying reports. My project uses SlickGrid v1.4. I want modify the current reports and implement tree view in the reports. I am passing the parent for each element from backend to UI.
Questions:
Do I need to upgrade slickgrid to its latest version. If yes then is it backward compatible?
How can I implement this parent child relationship in slickgrid, like what properties that I will be using?
Let me know if you need more details on this.
Thanks
If you are referring to the javascript slickgrid, then you need to specifically look at this example of slickgrid
https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example5-collapsing.html
This is an implementation rather than a feature so any version should be fine. So yes better go with latest if possible.
Its just an implementation of tree view using indents. Its different from other libraries where they have specific views for tree structure.
What you should do on the backend is, send an array with list of items to the frontend. the data item should have 2 attributes parent and level.
The parent will be null for root and level 0. if an item is child of some parent. The level of child will be 1 and parent 0 (index of array). (as implemented in slickgrid)
Please note parent value can be anything based on your data. For example a hierarchy of categories.
var item1 = {id: "id_1", category:"cat1" parent: null, }
var item2 = {id: "id_2", parent: "cat1"};
So the level attribute shows the depth of current item in the hierarchy.
The slick grid in the example uses the level value to put indents or spaces.
You can either use the same logic or may be apply specific css3 classes based on the level and customize according to your needs.
.class[level=0] {}
So slick grid is flexible that way. You just need the data in a particular format.
One important thing is the array of items should already be sorted by the field and level for this to work.
Some databases like Oracle already provide you options like connect by prior to get data in this format. there is a reserved keyword level which can be added as a column name.
Also this is assuming that you table is already designed in a way to represent hierarchal structure.
SELECT category_id, cat_name, cat_parent_id, LEVEL
FROM categories
CONNECT BY PRIOR category_id = cat_parent_id;
You can also fetch data from a specified root
START WITH category_id = 5

Sorting by column in an XPages view data source

I have a dynamic view control (my own) which is fed by a configurable view data source. I need to be able to sort the view by various columns. Is there a way to do it with the view data source or do I need to roll my own? Thanks for the help.
For efficiency reasons, sorting should be handled by the domino runtime. The view must have the right columns either tagged as sorted or sortable by user. This creates the indexes within the NSF.
Then, the data source has some properties to control with sort index in being used, based on the name of the column you want to sort. The extlib DataView controls shows how this can be done in Java, through a JSF DataModel.
Also, you might consider using the DynamicViewpanel from the extlib/up1, as it does all of this for you.

What's the easiest way to sort an EF4 EntityCollection<T>?

I'd love to add some sorting to an EntityCollection that is bound to an ItemsControl (in xaml). I'd also like to do it as simply as possible. It appears that this is not possible.
If I wrap the collection in a "sorted" version of the collection property within the Entity I lose collection change notifications. I can't use a CollectionViewSource because the entity collection's BindingListCollectionView does not support sorting for some goddamned reason (note: I've seen the blog post with the "dirty" hack to get around this, so please don't answer with that kthx).
Is there a simple (couple lines of xaml, couple lines of code, whatever) way to achieve this??
The EntityCollection type cannot be directly filtered or sorted. It's a common LINQ-to-Entities problem, see:
Sort child objects while selecting the parent using LINQ-to-Entities
One solution would be to sort the entity collection separately using LINQ when you need the data, and incur the additional performance hit. If you're working with a collection you expect to be small and/or infrequently used, the difference in processing time could be negligible.
If you want the database perform the sorting and make use of any indexes, you can project the main entity along with the child entities. Alex James posts an example in his MSDN blog: http://blogs.msdn.com/b/alexj/archive/2009/02/25/tip-1-sorting-relationships-in-entity-framework.aspx. You're not limited to anonymous types, of course.

Resources