jQWidgets Forums

jQuery UI Widgets Forums Grid 1 CSV file for multiple grids with column selection

This topic contains 7 replies, has 3 voices, and was last updated by  paulcobben 4 years, 1 month ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author

  • paulcobben
    Participant

    Hi,

    At this moment we generate a separate csv file per grid. For a set of dashboards this results in approx 15 csv files.

    We want to make only 1 data export from our own program to 1 large csv file that has all data. (We do not use a database)
    This will be a file with for example 150 columns and 1000 lines.

    Is it possible (or would be a nice feature) to select only the needed columns instead of defining all the 150 datafields.

    Example:

    datafields: [
                        { columnumber: 5, name: 'Date', type: 'date' },
                        { columnumber: 6, name: 'S&P 500', type: 'float' },
                        { columnumber: 12, name: 'NASDAQ', type: 'float' }
                    ],

    Hristo
    Participant

    Hello paulcobben,

    There is no such built-in functionality, unfortunately.
    You could export to variables that you could transform into only one.
    About the columns, you could set the exportable: false option to each one column that you do not want to be exported.
    Please, take a look at this topic:
    https://www.jqwidgets.com/community/topic/export-customise-grid-data/
    I hope this will help.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    Hi Hristo,

    I think i was not quite clear with my topic start.
    We have our own application (program) that exports a large csv.
    Then I want only that (1) csv for all my dashboards, where per dashboard I can select only the columns that are needed.
    So it is not about the export from a grid, but importing a csv into a grid.

    Kind Regards,
    Paul Cobben


    paulcobben
    Participant

    Still no solution till know, Searched the forum and internet. Anyone?


    Yavor Dashev
    Participant

    Hi paulcobben,

    I would suggest you to take a look at this example:
    https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/dataimport.htm

    You can load your file with all the datafields needed and after that you can set different and also set the columnsproperty hidden: to true.
    Then for every dashboard you can use the setcolumnproperty to make them visible and the others hidden.
    A bit of a code example on how to do this:

                    columns: [
                      { text: 'First Name', datafield: 'firstname', width: 130, hidden :true },
                      { text: 'Last Name', datafield: 'lastname', width: 130 },
                  
                    ]
                });
          
    
                $('#makeVisible').click(function () {
                    $('#grid').jqxGrid('setcolumnproperty', 'firstname', 'hidden', false);
                
                });

    Also another option for you could be this:
    https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm#demos/jqxgrid/tabs-and-grid.htm

    Let me know if that works for you!

    Please, do not hesitate to contact us if you have any additional questions.

    Best Regards,
    Yavor Dashev
    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    Hi Yavor Dashed,

    I am sorry.
    This does not solve my issue.
    When I have 1 CSV with 150 columns and 3000 lines, I still have to declare the 150 datafields.
    I only want to select 4, e.g. columns; 40, 41, 82 and 85. So I only want to declare those datafields as given in my topic start.
    Then your solution is not exactly what I mean.
    Is this even possible? Or is it a nice new feature in a future release?

    Kind Regards,
    Paul Cobben


    Yavor Dashev
    Participant

    Hi Paul,

    For this situation I can suggest you two possible solutions but without any code example from your side I can only guess exactly what you are trying to achieve.

    My first proposal is to create a dataAdapter which loads all the necessary datafields for the jqxGrid.
    A quick code snippet of what exactly I mean:

        <script type="text/javascript">
            $(document).ready(function () {
                var url = '../../sampledata/nasdaq_vs_sp500.txt';
    
                var source =
                {
                    datatype: "csv",
                    datafields: [
                        { name: 'Date', type: 'date' },
                        { name: 'S&P 500', type: 'float' },
                        { name: 'NASDAQ', type: 'float' }
                    ],
                    url: url
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#grid").jqxGrid(
                {
                    width: getWidth('Grid'),
                    source: dataAdapter,
                    columnsresize: true,
                    columns: [
                      { text: 'Date', datafield: 'Date', cellsformat: 'D', width: 250},
                      { text: 'S&P 500', datafield: 'S&P 500', width: 300, cellsformat: 'f' },
                    ]
                });
               
                $("#grid2").jqxGrid(
                    {
                        width: getWidth('Grid'),
                        source: dataAdapter,
                        columnsresize: true,
                        columns: [
                            { text: 'Date', datafield: 'Date', cellsformat: 'D', width: 250},
                            { text: 'NASDAQ', datafield: 'NASDAQ', cellsformat: 'f' }         
                            ]
                    });
            });
        </script>
    </head>
    <body class='default'>
        <div id="grid"></div>
        <br> <br>
        <div id="grid2"></div>
     

    The second option it to create separate dataAdapters for each grid like in this example:
    https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/tabs-and-grid.htm

    Please, do not hesitate to contact us if you have any additional questions.

    Best Regards,
    Yavor Dashev
    jQWidgets team
    https://www.jqwidgets.com


    paulcobben
    Participant

    Okay I try to explain it more easily.
    I have multiple html files with only 1 grid per html file.
    I have only 1 CSV file with 150 columns and 3000 lines.

    Now within jqwidgets defining a grid, I first have to declare ALL the columns from the CSV in the source section. So all 150 columns. Which I do not need in specific grids. I only want a part of that (only 1) CSV. I typed ‘…………’ because I did not want to type all the 150 datafields for this example.
    Example of code below:

    <script type="text/javascript">
            $(document).ready(function () {
                var url = '../../sampledata/nasdaq_vs_sp500.txt';
    
                var source =
                {
                    datatype: "csv",
                    datafields: [
                        { name: 'Column1', type: 'string' },
                        { name: 'Column2', type: 'string' },
                        { name: 'Column3', type: 'string' },
                        ............
                        { name: 'Column84', type: 'string' },
                        { name: 'Column85', type: 'string' },
                        ............
                        { name: 'Column150, type 'string' }
                    ],
                    url: url
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#grid").jqxGrid(
                {
                    width: getWidth('Grid'),
                    source: dataAdapter,
                    columnsresize: true,
                    columns: [
                      { text: 'Department', datafield: 'Column2',  width: 250},
                      { text: 'Manager',    datafield: 'Column84', width: 200},
                      { text: 'Building',   datafield: 'Column85', width: 100}
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id="grid"></div>
    </body>

    What would be nice, if you still could use the (only 1) CSV file with 150 columns, but in the source part only declare the datafields (columns in CSV file) that are needed for this specific grid.
    I know that my suggested columnnumber does not exist in your api reference, but I think it is a great new feature.
    Example below

    <script type="text/javascript">
            $(document).ready(function () {
                var url = '../../sampledata/nasdaq_vs_sp500.txt';
    
                var source =
                {
                    datatype: "csv",
                    datafields: [
                        { columnnumber: '2' , name: 'Column1', type: 'string' },
                        { columnnumber: '84', name: 'Column84', type: 'string' },
                        { columnnumber: '85', name: 'Column85', type: 'string' }
                    ],
                    url: url
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#grid").jqxGrid(
                {
                    width: getWidth('Grid'),
                    source: dataAdapter,
                    columnsresize: true,
                    columns: [
                      { text: 'Department', datafield: 'Column2',  width: 250},
                      { text: 'Manager',    datafield: 'Column84', width: 200},
                      { text: 'Building',   datafield: 'Column85', width: 100}
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id="grid"></div>
    </body>
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.