c# – 如何在两个jQuery数据表之间传递参数
发布时间:2020-12-15 21:40:31 所属栏目:百科 来源:网络整理
导读:我有两个数据表,一个列出了foldes,另一个列出了父文件夹中的文件.以下是我的脚本查找文件夹表的方式: var oTable = $('#folderTable').dataTable({ "bServerSide": true,"sAjaxSource": "AJAXViewFolders","bProcessing": true,"bFilter": false,"aoColumns
我有两个数据表,一个列出了foldes,另一个列出了父文件夹中的文件.以下是我的脚本查找文件夹表的方式:
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" } ] }); }); 现在,当用户单击链接时,我需要能够将该parentid传递给文件数据表.到目前为止,我没有运气.以下是JSON结果在我的控制器中对于数据文件的查找方式: 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); } 如何获取文件夹表中的链接以将parentid成功传递给文件数据表的jsonresult? 解决方法
我假设dataTables在同一页面上,所以我将它切换到一个按钮……
"fnRender": function (oObj) { return '<button type="button" class="folder-view" data-id="' + oObj.aData[0] + '">View</button>'; } 添加实时单击处理程序,以便您可以设置当前的parentid并刷新文件dataTable.处理程序可能看起来像这样…… $('.folder-view').on('click',function() { var $filesTable = $('#filesTable'); $filesTable.attr('data-parentid',$(this).attr('data-id')); //refresh the files table $filesTable.dataTable().fnDraw(false); }); 最后,文件dataTable将需要覆盖fnServerData函数以合并额外的parentid数据…… "fnServerData": function (sSource,aoData,fnCallback) { var extraData = [ { parentid: $('#filesTable').attr('data-parentid') } ]; $.ajax({ "dataType": "json","type": "POST","url": sSource,"data": $.merge(extraData,aoData),"success": fnCallback }); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |