我有一個應用程序,我使用JQGrid顯示數據(我是JQGrid的新手)。申請適用於不懂英語的客戶。因此,我們需要顯示的數據可以通過數據庫以樸素的語言顯示,因爲我需要使用csv文件顯示列名稱,網格標題,加載網格消息.....等。我查過並發現JQGrid沒有直接支持csv。但是,我們可以使用任何其他解決方法來做到這一點?如何導入csv文件到JqGrid
我會顯示我的代碼片段。
jQuery("#jQGrid").jqGrid({
url: 'Handler1.ashx',
datatype: 'json',
toppager: 'false',
height: 300,
colNames: [strPersonID, strLastName, strFirstName, strAddress, strCity],
colModel: [
{ name: 'ID', width: 60, index: 'ID', stype: 'text', search: false, sortable: true },
{ name: 'LastName', width: 100, index: 'LastName', stype: 'text', sortable: true },
{ name: 'FirstName', width: 100, index: 'FirstName', align: 'center', stype: 'text', classes: 'hyperlink', formatter: 'showlink', formatoptions: { baseLinkUrl: 'http://localhost:58404/About.aspx' } },
{ name: 'Address', width: 100, index: 'Address', stype: 'text', search: false, sortable: true },
{ name: 'City', width: 100, index: 'City', stype:'select', editoptions:{value:":;Bangalore:Bangalore;Chennai:Chennai;Pune:Pune;Bombay:Bombay;Lucknow:Lucknow;Delhi:Delhi;Agra:Agra"}, sortable: true }
],
rowNum: 10,
mtype: 'GET',
loadonce: true,
loadtext: strLoading,
rowList: [10, 20, 30],
viewrecords: true,
sortname: 'ID',
sortorder: 'desc',
caption: strListEmployeeDetails,
shrinkToFit: 'false'
});
這些列名,loadtext和Caption我必須從csv文件中提取。
爲同後面的代碼:
UIContentController uiContentController = new UIContentController();
string strPersonID = uiContentController.GetText("Start_JqGrid_strPersonID", null);
string strLastName = uiContentController.GetText("Start_JqGrid_strLastName", null);
string strFirstName = uiContentController.GetText("Start_JqGrid_strFirstName", null);
string strAddress = uiContentController.GetText("Start_JqGrid_strAddress", null);
string strCity = uiContentController.GetText("Start_JqGrid_strCity", null);
string strListEmployeeDetails = uiContentController.GetText("Start_JqGrid_strListEmployeeDetails", null);
string strLoading = uiContentController.GetText("Start_JqGrid_strLoading", null);
jqGridColConstant = jqGridColConstant + "var strPersonID = '" + strPersonID + "';";
jqGridColConstant = jqGridColConstant + "var strLastName = '" + strLastName + "';";
jqGridColConstant = jqGridColConstant + "var strFirstName = '" + strFirstName + "';";
jqGridColConstant = jqGridColConstant + "var strAddress = '" + strAddress + "';";
jqGridColConstant = jqGridColConstant + "var strCity = '" + strCity + "';";
jqGridColConstant = jqGridColConstant + "var strListEmployeeDetails = '" + strListEmployeeDetails + "';";
jqGridColConstant = jqGridColConstant + "var strLoading = '" + strLoading + "';";
jqGridColConstant = jqGridColConstant + "</script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered("jqGridColConstant"))
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jqGridColConstant", jqGridColConstant);
我的CSV文件條目是:
246,Start_JqGrid_strPersonID,Person_ID
247,Start_JqGrid_strLastName,Last Name
248,Start_JqGrid_strFirstName,First Name
249,Start_JqGrid_strAddress,Address
250,Start_JqGrid_strCity,City
251,Start_JqGrid_strListEmployeeDetails,Employee Details
252,Start_JqGrid_strLoading,Loading...
目前這是英文的,但會進一步的客戶會根據自己的需要更改csv文件
這種方法沒有給出預期的結果。 任何解決方案或解決方法? 請幫忙。