On page load my model gets passed in with a List of Event logs from a machine. I declare a list and then fill it with those logs.
private List<machine_log> _logObjList = new List<machine_log>();
which gets filled up via this:
@helper FillLogMainList()
{
foreach (IQueryable<machine_log> logType in Model.MachineLogs)
{
foreach (var log in logType)
{
_logObjList.Add(log);
}
}
}
These logs can have 6 different types. Application, System, Security, etc. I want to just show one type in the webgrid. Which I can do now. The issue comes when I have already loaded say, "Application Logs" but I want to click the "Security Logs" button to now populate the grid with Secutity type logs from the _logObjList list I already have.
When I first open the page, the default "Application Logs" gets filled via this function where I pass "application" in as the type string:
@helper FillLogList(string type)
{
_logs.Clear();
foreach (var log in _logObjList)
{
if (log.log_type == type)
{
string entry = "";
if (log.entry_type == "Warning ")
{
entry = "http://trycatchgaming.com/temp/warning.png";
}
else
{
entry = "http://trycatchgaming.com/temp/error.png";
}
var newLine = new SingleLog
{
EntryType = entry,
Message = log.event_id + "#" + log.message,
Source = log.source,
EventId = log.event_id,
LogId = log.id,
EntryTime = log.entry_time
};
_logs.Add(newLine);
}
}
}
Now I have a list for _logs that I populate the webgrid with, which is part of the normal "body" of the page inside a div:
<div id="grid" style="padding: 0; overflow-y: scroll; height: 500px; width: 100%">
@obj = new WebGrid(source: _logs, defaultSort: "EntryTime", ajaxUpdateContainerId: "grid", rowsPerPage: 200000);
@obj.GetHtml(
tableStyle: "webgrid-table",
htmlAttributes: new { id = "MainTable" },
headerStyle: "webgrid-header",
//footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
//mode: WebGridPagerModes.All,
columns: obj.Columns(
obj.Column(columnName: "EntryType", header: "Event Type", format:@<img src="@item.EntryType" />),
obj.Column(columnName: "EntryTime", header: "Event Time"),
obj.Column(columnName: "Source", header: "Source"),
obj.Column(columnName: "EventId", header: "Event Id"),
obj.Column(columnName: "LogId", header: "Log Id"),
obj.Column(header: "All", style: "labelcolumn", format: @<text><input class="check-box" tag="check-box" id="assignChkBx" name="Message" type="checkbox" value="@item.Message" /></text>)
)
)
</div>
So, my question boils down to, I know how to clear and make a new list of logs and everything, but I have no idea how to apply that to the grid. Ideally I could just clear the logs list, populate it with Security logs, then refresh the grid, which would now be populated with security logs. Wash rinse repeat.
However there seems to not be any built in methods for handling data this way. All the examples I can find want me to go back to the controller, get more data and refill the grid via some partial view. HOWEVER, I already have all the data, and I would prefer to not have to make additional queries and loads just to get data I already have.