Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Filtering and Ordering JSON for datatable (custom datasource for sitemap)

$
0
0

Hello...

For starters, I am working with Newtonsoft.JSON - I thought this category might be the best place to answer my question, as it is highly relatable to an pureblood APUI.
My desired data flow is the following:
- Json string
- Filtering Json
- Order Json (prepare for datatable)
- Move to datatable (for an repeater item to databind html to it)

What I will be using the data for is for an menu.

I have the following example JSON:

{"siteMap": {"siteMapNode": [
			{"title": "Intro","description": "Intro Pages","type": "intro","siteMapNode": [
					{"title": "Welcome","description": "Landing Page","url": "/Default.aspx"
					},
					{"title": "About Us","description": "What/Who are We","url": "/About.aspx"
					},
					{"title": "Contact Us","description": "Contact Form","url": "/Contact.aspx"
					}
				]
			},
			{"title": "Event Participation","description": "A Event is normally chosen to be here","type": "event","retainQuery": "secret","siteMapNode": [
					{"title": "Event Details","description": "Training","url": "/Event.aspx","retainQuery": "secret"
					},
					{"title": "Scoreboard","description": "See top scores","url": "/Scoreboard.aspx","retainQuery": "secret"
					},
					{"title": "Team Management","description": "Create Team/Join Team/View Team","url": "/EventTeam.aspx","retainQuery": "secret"
					},
					{"title": "Participate","description": "Interface with out Smart Beerbong and Participate","url": "/EventParticipate.aspx","retainQuery": "secret"
					}
				]
			},
			{"title": "Event Organizer","description": "Organize Events","type": "organizer","role": "organizer","siteMapNode": [
					{"title": "\"My Events","description": "Shows Events you are assigned","url": "/Organizer/MyEvents.aspx"
					},
					{"title": "Edit Events","description": "Edit selected event","url": "/Organizer/EventOrganizer.aspx","retainQuery": "secret","hide": "true"
					}
				]
			},
			{"title": "Admin","description": "Administrator for Platform","type": "admin","role": "admin","siteMapNode": [
					{"title": "User Management","description": "Manage Users","url": "/Admin/UserManagement.aspx"
					},
					{"title": "Event Management","description": "Manage Events","url": "/Admin/EventManagement.aspx"
					}
				]
			},
			{"title": "System/Debug","description": "System Debug Info","type": "admin","role": "admin","siteMapNode": {"title": "Event Management","description": "Manage Events","url": "/Admin/Info.aspx"
				}
			}
		]
	}
}

So as you see x.siteMap.siteMapNode[*] is mostly a 'category' placeholder, meaning it does not contain an url nor should the attributes be read 'directly' from it, but inherited unless other is specified in the x.siteMap.siteMapNode[*].siteMapNode[*]

So the filtering should mostly be done based on firstly "url", "role"(multiple roles elements), "hide". quick explanation of the different filtering parameters:
url = current url (meaning whole x.siteMap.siteMapNode[*] containing the siteMapNode with the url should be returned) ()
role = if user has correct role to see pages - can be given as list of strings, or checked with !Roles.IsUserInRole(User.Identity.Name, "%rolename%")
hide = means if it should be ignored for the menu generation (not set means false)
retainQuery = means it will populate the url with the currect url named quetry string name, example "?secret=hey", will populate the other returned urls in the 'category'

To illustrate three scenarios and returned data for the desired datatable it should look something like this(with desired integration for datatable): (full size illustration here:https://i.imgur.com/9LuzOWT.png)


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>