jQWidgets Forums

jQuery UI Widgets Forums Grid Include list values in a single data row

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  ivailo 10 years ago.

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

  • jhasell
    Participant

    I have a class much like the following:
    public class foo_class
    {
    public int a { get; set; }
    public int b { get; set; }
    public string c { get; set; }
    public List<int> d { get; set; }
    }

    What I would like to do is display a collection of this class in a jquery grid, displaying all elements of d in the same row as a, b and c, like so:
    a1 | b1 | c1 | d1[0] | d1[1] | d1[2] | …
    a2 | b2 | c2 | d2[0] | d2[1] | d2[2] | …
    a3 | b3 | c3 | d3[0] | d3[1] | d3[2] | …

    The problem is that the d list is not a fixed size; in fact, its size can change at runtime depending on what the user does.

    The best I have come up with so far is the following, using the jqwidgets grid:
    var source =
    {
    datatype: “json”,
    datafields: [
    { name: ‘a’, type: ‘int’ },
    { name: ‘b’, type: ‘int’ },
    { name: ‘c’, type: ‘string’ },
    ],
    id: ‘id’,
    localdata: data.foo
    };

    var myColumns = [
    { datafield: “a”, text: “a”, width: 60 },
    { datafield: “b”, text: “b”, width: 250 },
    { datafield: “c”, text: “c”, width: 75 },
    ];

    for (i = 0; i < data.d.Count; i++) {
    source.datafields.push({ name: “d[” + i + “]”, type: “int”, map: “d[” + i + “]” });
    myColumns.push({ datafield: “d[” + i + “]”, text: i, width: 75 });
    };

    var dataAdapter = new $.jqx.dataAdapter(source);
    $(“#jqxgrid”).jqxGrid(
    {
    source: dataAdapter,
    columns: myColumns
    });

    This displays the a, b, c data and the columns for d, but the grid cells for the d values are blank. Can anyone tell me what I am doing wrong? I am a newbie to jquery stuff.


    ivailo
    Participant

    Hi jhasell,

    Send a fiddle with your actual data for better visualization of the problem.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.