I have two datatables, one which lists foldes, and another which list’s files within their parent folder. Here is how my script looks for the folder table:
var oTable = $('#folderTable').dataTable({
"bServerSide": true,
"sAjaxSource": "AJAXViewFolders",
"bProcessing": true,
"bFilter": false,
"aoColumns": [
{ "sName": "folder_id",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"ViewFiles?parentid=' + oObj.aData[0] + '\">View</a>';
}
},
{ "sName": "folder_name" },
{ "sName": "create_date" }
]
});
});
Now, when the user clicks the link I need to be able to pass that parentid to the file datatable. I have had no luck thus far. Here is how the JSON result looks in my controller, for the files datatable:
public JsonResult AJAXViewFiles(DataTableParamModel dtParams, int parentid)
{
var repo = new TrusteeDocumentRepository();
var allDocuments = repo.FindAllFiles().Where(c=>c.folder_id == parentid);
IEnumerable<Files> filteredFiles;
filteredFiles = allDocuments;
var displayedFiles = filteredFiles.Skip(dtParams.iDisplayStart).Take(dtParams.iDisplayLength);
var result = from c in displayedFiles select new[] { Convert.ToString(c.folder_id),c.file_name, c.upload_date.ToString() };
return Json(new
{
sEcho = dtParams.sEcho,
iTotalRecords = allDocuments.Count(),
iTotalDisplayRecords = filteredFiles.Count(),
aaData = result
},
JsonRequestBehavior.AllowGet);
}
How would I go about getting the link in the folder table to pass the parentid to the jsonresult for the file’s datatable successfully?
I assume the dataTables are on the same page so I’d switch it to a button…
Add a live click handler so you can set the current parentid and refresh the files dataTable. Handler might look like this…
Finally, the files dataTable will need to override the
fnServerDatafunction to merge the extra parentid data…