2014-01-28 68 views
-1

我有一个应用程序,我使用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文件

这种方法没有给出预期的结果。 任何解决方案或解决方法? 请帮忙。

回答

0

我很惊讶地知道,没有人甚至试图回答我的问题.....

大部分的谷歌搜索的说,没有直接支持从CSV导入数据/ jqGrid的属性值。

所以最后经过一些研究,我在自己的问题上得到了答案。它是这样的:

上面的代码示例中唯一的变化是在.ascx文件只有在声明列名的时候,LoadText &标题....

colNames: [''+strPersonID+'', ''+strLastName+'', ''+strFirstName+'', ''+strAddress+'', ''+strCity+''], 
loadtext: ''+strJQGridLoadingMessage+'', 
caption: ''+strCurrentRequestHeaderCaption+'', 

请注意,它不是双核我在那里使用它的两个单核只有 .... 使用这个我能够实现我想要的。

Thanks All, Aashu ...