1

I'm currently new to Javascript and right now using this JS-grid in an Example about Prime Numbers. I have an Array with Prime Numbers: Array(4) [ " 2", " 3", " 5", " 7" ].

Which the console.log shows is populated with these values. I'd like to import it into the JS-Grid but it never displays the values in each row, but only all Values of the Array in one row. Here is my configuration right now:

var clients = [{
    "Primenumber": Primenumber
}];

$("#jsGrid").jsGrid({
    width: "100%",
    height: "400px",

    inserting: true,
    editing: true,
    sorting: true,
    paging: true,

    data: clients,

    fields: [{
            name: "Primenumber",
            type: "text",
            width: 150
        },{
            type: "control"
        }
    ]
});

Am I importing the Array into the JS-Grid wrong? I'm not sure how to display each value of the Array in a seperate row. Thank you guys in Advance for your Answer!

1 Answer 1

1

Per the documentation:

data An array of items to be displayed in the grid. The option should be used to provide static data. Use the controller option to provide non static data.

I noticed that you are only passing an array with one value to the data key

var clients = [{
  "Primenumber": Primenumber
];

This is equivalent to passing:

var clients = [{
  Primenumber: [" 2", " 3", " 5", " 7"]
}]

and even though the Primenumber key has an associated value with multiple elements, the containing object itself is only a single value inside of the array.

I wonder what happens if you instead pass:

var clients = Primenumber;

and in doing so, you're passing the array itself.

Finally, to have your values show up, you have to have them in the data array as keyvalue pairs:

var Primenumber = [{Primenumber:" 2"}, {Primenumber: " 3"}, {Primenumber: " 5"}, {Primenumber: " 7"},];
var clients = Primenumber;

Working example here

Illustrative example in the official documentation here

Sign up to request clarification or add additional context in comments.

1 Comment

i tried directly passing the Value, now the grid shows 4 empty rows but not the actual Numbers. Do i need to loop through the Array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.