如何将csv文件导入JqGrid

时间:2014-01-28 07:14:30

标签: jquery jquery-ui csv jqgrid

我有一个应用程序,我使用JQGrid显示数据(我是JQGrid的新手)。申请是针对不懂英语的客户。因此,我们需要显示的数据可以通过DB以天真的语言显示,我需要使用csv文件显示列名,网格标题,加载网格消息.....等。我搜索过并发现JQGrid中没有对csv的直接支持。但我们可以使用任何其他解决方法吗?

我将展示我的代码段。

    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文件

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

1 个答案:

答案 0 :(得分:0)

我很惊讶地发现没有人试图回答我的问题......

大多数谷歌搜索说没有直接支持从csv导入数据/ JQGrid属性值。

所以经过一些研究后我终于得到了自己的答案。它是这样的:

上述代码示例中的更改仅在声明列名称时才会在.ascx文件中,LoadText&amp;字幕....

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

请注意,它不是双核我只使用了两个单核 .... 使用它我也能实现我想要的目标。

全部谢谢, Aashu ...