Display Data Based On Logged In User
Display Data Based On Logged In User
![l337method](https://images.v-cdn.net/banned_large.png)
Hello!
I have been trying to research this for a while now, but haven't been able to find a good example to check out. What I would like to accomplish is to have my DataTable display only data relevant to the user that is currently logged in (and then have an admin account that can see everything). I am using ASP.Net MVC 5 with Windows Authentication which doesn't have a traditional login screen built into it (it just does that quick check and logs in the user). The way that I would have done it in the past is have the user log in using a login screen, store their information into a session variable, and then work off of that. Is something similar to that possible with DataTables?
Here is a fiddle of my DataTable:
https://jsfiddle.net/l337method/hfyo90w7/
This question has an accepted answers - jump to answer
Answers
This is not really a Datatables issue. My first question is how are you fetching the data?
If using AJAX then pass the user ID using the AJAX data option and let the server script retrieve the correct data based on the user ID. If you rely on Datatables to filter the data based on the ID you could potentially have data at the client the user shouldn't see but can get to outside of Datatables.
Kevin
Thanks for the response!
The data is being pulled from an SQL database that I had made in SQL Server Management Studio. I agree with your statement about using DataTables to filter the information. I was hoping to have a way to store the users information and then when the view is selected that uses DataTables it would check for the users ID and then display the relevant data (without any user input).
You are right though. It is more of a ASP.Net question than a DataTables question. :P
If you are initializing the Datatable after the user login info is available you could use the
search
to setup a default search based on the ID or you could use thesearch
API. Along with not providing the default search box.Not sure the source of the data for Datatables (dom, JS, ajax) but if JS you could use
rows.add()
to add the relevant rows.Not sure if any of these ideas are useful.
Kevin
At the very least it gives me some options to check out. Thank you, sir.![:D :D](https://datatables.net/forums/resources/emoji/lol.png)