jQWidgets Forums

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Dynamic jqxGrid Dynamic jqxGrid #97303

    debear
    Participant

    Hello. I’m sorry it took so long. In the sample application, every time I press the button I create a random number of data. The data is transmitted to the grid control.

    
    import React, { Component } from 'react';
    import JqxGrid from 'jqwidgets-framework/jqwidgets-react/react_jqxgrid.js';
    
    class CreateDataComponent extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                gridData: new Array()
            };
        }
    
        createAndSendData() {
            var dataSize = Math.floor((Math.random() * 5) + 1);
            var data = [];
            var result = new Array();
            for (var i = 0; i < dataSize; i++) {
                data.push({ key: "Header_" + i, value: i });
            }
            this.setState({
                gridData: data
            });
        }
    
        render() {
            return (
                <div>
                    <GridComponent data={this.state.gridData}/>
                    <button ref="btnData"  onClick={this.createAndSendData.bind(this)}>Create and send data</button>
                </div>
            )
        }
    }
    
    class GridComponent extends React.Component {
        componentWillReceiveProps(nextProps) {
            this.createGrid(nextProps.data);
        }
    
        createDataFiels(data) {
            var result = new Array();
            if (data != null) {
                data.forEach((item, index) => {
                    var dataName = "data" + index;
                    result.push({ name: dataName, type: 'number' })
                });
            }
            return result;
        }
    
        createColumns(data) {
            var result = new Array();
            if (data != null) {
                data.forEach((item, index) => {
                    var dataName = "data" + index;
                    result.push({ text: item.key, datafield: dataName, columntype: "numberinput", width: 200 });
                });
            }
            return result;
        }
    
        createLocalData(data) {
            var result = new Array();
            if (data != null) {
                var lc = {};
                data.forEach((item, index) => {
                    var dataName = "data" + index;
                    lc[dataName] = item.value;
                });
                result.push(lc);
            }
            return result;
        }
    
        createGrid(data) {
            var columns = this.createColumns(data);
            var source = {
                datatype: 'local',
                datafields: this.createDataFiels(data),
                localdata: this.createLocalData(data)
            };
            var dataAdapter = new jqx.dataAdapter(source);
    
            this.refs.grid.beginupdate(true);
            //this.refs.grid.columns = columns;
            //this.refs.grid.source = dataAdapter;
            this.refs.grid.setOptions
                ({
                    source: dataAdapter,
                    columns: columns
                });
    
            this.refs.grid.endupdate();
        }
    
        render() {
            return (
                <div>
                    <JqxGrid
                        ref='grid'
                        editable={true}
                        showemptyrow={true}
                        height={200}
                    />
                </div>
            )
        }
    }
    
    export default CreateDataComponent;
    

    Best Regards,
    debear

    in reply to: Dynamic jqxGrid Dynamic jqxGrid #97207

    debear
    Participant

    Thank you for your answer. This solution works well. I have a question in to the code from the previous post.
    When I set the columns, I checked how the grid control was generated. I was curious that the columns are not overwritten just added. Grid displayed rows of data well, but columns only after removing additional divs and leaving the last div. Maybe it’s a bug in the control.
    The following code shows the situation.
    Passed two columns:

    
    <div style="overflow: hidden; display: block; height: 30px; width: 1002px; visibility: inherit;" class="jqx-widget-header jqx-grid-header">
    	<div id="columntablejqxGridjqx39d84e01243e" style="height: 100%; position: relative; visibility: inherit; width: 402px; margin-left: 0px;">
    		<div role="columnheader" style="z-index: 29; position: absolute; height: 100%; width: 200px; left: 0px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 200px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    	</div>
    </div>
    

    Passed four columns

    
    <div style="overflow: hidden; display: block; height: 30px; width: 1002px; visibility: inherit;" class="jqx-widget-header jqx-grid-header">
    	<div id="columntablejqxGridjqx39d84e01243e" style="height: 100%; position: relative; visibility: inherit; width: 402px; margin-left: 0px;">
    		<div role="columnheader" style="z-index: 29; position: absolute; height: 100%; width: 200px; left: 0px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 200px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    	</div>
    	<div id="#columntablejqxGridjqxead941538e4b" style="height: 100%; position: relative; visibility: inherit; width: 402px; margin-left: 0px;">
    		<div role="columnheader" style="z-index: 29; position: absolute; height: 100%; width: 200px; left: 0px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 200px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 27; position: absolute; height: 100%; width: 200px; left: 400px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 600px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    	</div>
    </div>
    

    Passed five columns

    
    <div style="overflow: hidden; display: block; height: 30px; width: 1002px; visibility: inherit;" class="jqx-widget-header jqx-grid-header">
    	<div id="columntablejqxGridjqx39d84e01243e" style="height: 100%; position: relative; visibility: inherit; width: 402px; margin-left: 0px;">
    		<div role="columnheader" style="z-index: 29; position: absolute; height: 100%; width: 200px; left: 0px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 200px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    	</div>
    	<div id="#columntablejqxGridjqxead941538e4b" style="height: 100%; position: relative; visibility: inherit; width: 402px; margin-left: 0px;">
    		<div role="columnheader" style="z-index: 29; position: absolute; height: 100%; width: 200px; left: 0px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 200px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 27; position: absolute; height: 100%; width: 200px; left: 400px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 26; position: absolute; height: 100%; width: 200px; left: 600px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    	</div>
    	<div id="##columntablejqxGridjqxffdaeb006c15" style="height: 100%; position: relative; visibility: inherit; width: 402px; margin-left: 0px;">
    		<div role="columnheader" style="z-index: 29; position: absolute; height: 100%; width: 200px; left: 0px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 28; position: absolute; height: 100%; width: 200px; left: 200px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 27; position: absolute; height: 100%; width: 200px; left: 400px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 26; position: absolute; height: 100%; width: 200px; left: 600px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    		<div role="columnheader" style="z-index: 25; position: absolute; height: 100%; width: 200px; left: 800px;" class="jqx-grid-column-header jqx-widget-header">...<div>
    	</div>
    </div>
    
Viewing 2 posts - 1 through 2 (of 2 total)