jQuery UI Widgets Forums Grid Collapse the nested grid columns

This topic contains 3 replies, has 3 voices, and was last updated by  Dimitar 11 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Collapse the nested grid columns #12640

    himaja
    Member

    Hi,

    On a button click I need to collapse the expanded row details grid columns.
    Can you please suggest a solution for this.

    Thanks,
    Himaja

    Collapse the nested grid columns #12641

    Dimitar
    Participant

    Hello Himaja,

    To do this, you need to use the hiderowdetails method, as shown in the following example (based on the Nested Grids demo):

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title id='Description'>This example shows how to display nested Grid plugins.</title>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var theme = "";
    var url = "../sampledata/employees.xml";
    var source =
    {
    datafields: [
    { name: 'FirstName' },
    { name: 'LastName' },
    { name: 'Title' },
    { name: 'Address' },
    { name: 'City' }
    ],
    root: "Employees",
    record: "Employee",
    id: 'EmployeeID',
    datatype: "xml",
    async: false,
    url: url
    };
    var employeesAdapter = new $.jqx.dataAdapter(source);
    var orderdetailsurl = "../sampledata/orderdetails.xml";
    var ordersSource =
    {
    datafields: [
    { name: 'EmployeeID' },
    { name: 'ShipName' },
    { name: 'ShipAddress' },
    { name: 'ShipCity' },
    { name: 'ShipCountry' },
    { name: 'ShippedDate' }
    ],
    root: "Orders",
    record: "Order",
    datatype: "xml",
    url: orderdetailsurl,
    async: false
    };
    var ordersDataAdapter = new $.jqx.dataAdapter(ordersSource, { autoBind: true });
    orders = ordersDataAdapter.records;
    // create nested grid.
    var initrowdetails = function (index, parentElement, gridElement, record) {
    var id = record.uid.toString();
    var grid = $($(parentElement).children()[0]);
    var filtergroup = new $.jqx.filter();
    var filter_or_operator = 1;
    var filtervalue = id;
    var filtercondition = 'equal';
    var filter = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
    // fill the orders depending on the id.
    var ordersbyid = [];
    for (var m = 0; m < orders.length; m++) {
    var result = filter.evaluate(orders[m]["EmployeeID"]);
    if (result)
    ordersbyid.push(orders[m]);
    }
    var orderssource = { datafields: [
    { name: 'EmployeeID' },
    { name: 'ShipName' },
    { name: 'ShipAddress' },
    { name: 'ShipCity' },
    { name: 'ShipCountry' },
    { name: 'ShippedDate' }
    ],
    id: 'OrderID',
    localdata: ordersbyid
    }
    if (grid != null) {
    grid.jqxGrid({ source: orderssource, theme: theme, width: 600, height: 200,
    columns: [
    { text: 'Ship Name', datafield: 'ShipName', width: 200 },
    { text: 'Ship Address', datafield: 'ShipAddress', width: 200 },
    { text: 'Ship City', datafield: 'ShipCity', width: 150 },
    { text: 'Ship Country', datafield: 'ShipCountry', width: 150 },
    { text: 'Shipped Date', datafield: 'ShippedDate', width: 200 }
    ]
    });
    }
    }
    var photorenderer = function (row, column, value) {
    var name = $('#jqxgrid').jqxGrid('getrowdata', row).FirstName;
    var imgurl = '../../images/' + name.toLowerCase() + '.png';
    var img = '<div style="background: white;"><img style="margin:2px; margin-left: 10px;" width="32" height="32" src="' + imgurl + '"></div>';
    return img;
    }
    var renderer = function (row, column, value) {
    return '<span style="margin-left: 4px; margin-top: 9px; float: left;">' + value + '</span>';
    }
    // creage jqxgrid
    $("#jqxgrid").jqxGrid(
    {
    width: 670,
    height: 365,
    source: source,
    theme: theme,
    rowdetails: true,
    rowsheight: 35,
    initrowdetails: initrowdetails,
    rowdetailstemplate: { rowdetails: "<div id='grid' style='margin: 10px;'></div>", rowdetailsheight: 220, rowdetailshidden: true },
    ready: function () {
    $("#jqxgrid").jqxGrid('showrowdetails', 1);
    },
    columns: [
    { text: 'Photo', width: 50, cellsrenderer: photorenderer },
    { text: 'First Name', datafield: 'FirstName', width: 100, cellsrenderer: renderer },
    { text: 'Last Name', datafield: 'LastName', width: 100, cellsrenderer: renderer },
    { text: 'Title', datafield: 'Title', width: 180, cellsrenderer: renderer },
    { text: 'Address', datafield: 'Address', width: 300, cellsrenderer: renderer },
    { text: 'City', datafield: 'City', width: 170, cellsrenderer: renderer }
    ]
    });
    $("#hideRowDetails").click(function () {
    $('#jqxgrid').jqxGrid('hiderowdetails', 1);
    });
    });
    </script>
    </head>
    <body class='default'>
    <button id="hideRowDetails">
    Hide row details of second row</button>
    <div id="jqxgrid">
    </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Collapse the nested grid columns #12643

    RavikumarR
    Member

    hi Dimitar,
    i try to get the nested band row details . the row details not coming correctly.

    Ex :

    $(“#hideRowDetails”).click(function () {
    $(‘#jqxgrid’).jqxGrid(‘hiderowdetails’, 1);
    var ls = $(‘#jqxgrid’).jqxGrid(‘getrowdetails’, 1);
    alert(ls);
    var rows = $(‘#grid’).jqxGrid(‘getrows’);
    alert(rows);
    });

    in the above code the rows return only last few rows returned.

    Collapse the nested grid columns #12704

    Dimitar
    Participant

    Hello RavikumarR,

    Please check out the following example:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title id='Description'>This example shows how to display nested Grid plugins.</title>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var theme = "";
    var url = "../sampledata/employees.xml";
    var source =
    {
    datafields: [
    { name: 'FirstName' },
    { name: 'LastName' },
    { name: 'Title' },
    { name: 'Address' },
    { name: 'City' }
    ],
    root: "Employees",
    record: "Employee",
    id: 'EmployeeID',
    datatype: "xml",
    async: false,
    url: url
    };
    var employeesAdapter = new $.jqx.dataAdapter(source);
    var orderdetailsurl = "../sampledata/orderdetails.xml";
    var ordersSource =
    {
    datafields: [
    { name: 'EmployeeID' },
    { name: 'ShipName' },
    { name: 'ShipAddress' },
    { name: 'ShipCity' },
    { name: 'ShipCountry' },
    { name: 'ShippedDate' }
    ],
    root: "Orders",
    record: "Order",
    datatype: "xml",
    url: orderdetailsurl,
    async: false
    };
    var ordersDataAdapter = new $.jqx.dataAdapter(ordersSource, { autoBind: true });
    orders = ordersDataAdapter.records;
    // create nested grid.
    var initrowdetails = function (index, parentElement, gridElement, record) {
    var id = record.uid.toString();
    var grid = $($(parentElement).children()[0]);
    var filtergroup = new $.jqx.filter();
    var filter_or_operator = 1;
    var filtervalue = id;
    var filtercondition = 'equal';
    var filter = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
    // fill the orders depending on the id.
    var ordersbyid = [];
    for (var m = 0; m < orders.length; m++) {
    var result = filter.evaluate(orders[m]["EmployeeID"]);
    if (result)
    ordersbyid.push(orders[m]);
    }
    var orderssource = { datafields: [
    { name: 'EmployeeID' },
    { name: 'ShipName' },
    { name: 'ShipAddress' },
    { name: 'ShipCity' },
    { name: 'ShipCountry' },
    { name: 'ShippedDate' }
    ],
    id: 'OrderID',
    localdata: ordersbyid
    }
    if (grid != null) {
    grid.jqxGrid({ source: orderssource, theme: theme, width: 600, height: 200,
    columns: [
    { text: 'Ship Name', datafield: 'ShipName', width: 200 },
    { text: 'Ship Address', datafield: 'ShipAddress', width: 200 },
    { text: 'Ship City', datafield: 'ShipCity', width: 150 },
    { text: 'Ship Country', datafield: 'ShipCountry', width: 150 },
    { text: 'Shipped Date', datafield: 'ShippedDate', width: 200 }
    ]
    });
    }
    }
    var photorenderer = function (row, column, value) {
    var name = $('#jqxgrid').jqxGrid('getrowdata', row).FirstName;
    var imgurl = '../../images/' + name.toLowerCase() + '.png';
    var img = '<div style="background: white;"><img style="margin:2px; margin-left: 10px;" width="32" height="32" src="' + imgurl + '"></div>';
    return img;
    }
    var renderer = function (row, column, value) {
    return '<span style="margin-left: 4px; margin-top: 9px; float: left;">' + value + '</span>';
    }
    // creage jqxgrid
    $("#jqxgrid").jqxGrid(
    {
    width: 670,
    height: 365,
    source: source,
    theme: theme,
    rowdetails: true,
    rowsheight: 35,
    initrowdetails: initrowdetails,
    rowdetailstemplate: { rowdetails: "<div id='grid' style='margin: 10px;'></div>", rowdetailsheight: 220, rowdetailshidden: true },
    ready: function () {
    $("#jqxgrid").jqxGrid('showrowdetails', 1);
    },
    columns: [
    { text: 'Photo', width: 50, cellsrenderer: photorenderer },
    { text: 'First Name', datafield: 'FirstName', width: 100, cellsrenderer: renderer },
    { text: 'Last Name', datafield: 'LastName', width: 100, cellsrenderer: renderer },
    { text: 'Title', datafield: 'Title', width: 180, cellsrenderer: renderer },
    { text: 'Address', datafield: 'Address', width: 300, cellsrenderer: renderer },
    { text: 'City', datafield: 'City', width: 170, cellsrenderer: renderer }
    ]
    });
    $("#getRowDetails").click(function () {
    var rows = $("#grid").jqxGrid('getrows');
    var rowsString = "";
    for (var i = 0; i < rows.length; i++) {
    rowsString += i + " row ship name: " + rows[i].ShipName + "\n";
    };
    alert(rowsString);
    });
    });
    </script>
    </head>
    <body class='default'>
    <button id="getRowDetails">
    Get row details</button>
    <div id="jqxgrid">
    </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.