jQWidgets Forums

jQuery UI Widgets Forums Grid Can't get the cell values when click a cell

This topic contains 2 replies, has 2 voices, and was last updated by  micmor 10 years, 9 months ago.

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

  • micmor
    Participant

    Hi!
    i’ve tried for hours to get the value of the selected cell as in the exemple. I ca’t figure out where is the fail.
    the grid data is show
    when i click a cell it’s get marked but the values do net get showed.
    here’s my code:

    
    var dataAdapter = new $.jqx.dataAdapter(source);
        $("#dataTable").jqxGrid(
        {
            width: 1050,
            theme: 'office',            
            source: dataAdapter,
            columnsResize: true,
            selectionmode:'singlecell',
            columns: [
              { text: 'Vecka', dataField: 'veckarad', width: 50 },
              { text: 'fr.o.m.', dataField: 'fDate', width: 50 },
              { text: 't.o.m.', dataField: 'tDate', width: 50 },
              { text: 'ons 20-21(3)', dataField: 'pass1', width: 100 },
              { text: 'tor 20-21(7)', dataField: 'pass2', width: 100 },
              { text: 'lör 12-13(7)', dataField: 'pass3', width: 100 },
              { text: 'lör 14-15(5)', dataField: 'pass4', width: 100 },
              { text: 'lör 17-18(5)', dataField: 'pass5', width: 100 },
              { text: 'lör 17-18(6)', dataField: 'pass6', width: 100 },
              { text: 'sön 09-10(4)', dataField: 'pass7', width: 100 },
              { text: 'sön 12-13(7)', dataField: 'pass8', width: 100 },
              { text: 'sön 13-14(7)', dataField: 'pass9', width: 100 }          
            ]
        });
    
    $("#dataTable").on('cellselect', function (event) {
            var columnheader = $("#dataTable").jqxGrid('getcolumn', event.args.datafield).text;
            $("#selectedcell").html("Row: " + event.args.rowindex + ", Column: " + columnheader);

    ´

    and the html:

    <div><span id="selectedcell"></span></div>
    <div id="dataTable"></div> 
    

    thanks in advance!
    Michel


    Nadezhda
    Participant

    Hello Michel,

    Here is working example with your code:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>    
        <link rel="stylesheet" href="../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../scripts/jquery.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/jqxlistbox.js"></script>
        <script type="text/javascript" src="../jqwidgets/jqxdropdownlist.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.columnsresize.js"></script>
        <script type="text/javascript" src="../jqwidgets/jqxgrid.filter.js"></script>
        <script type="text/javascript" src="../jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="../jqwidgets/jqxgrid.pager.js"></script>
        <script type="text/javascript" src="../jqwidgets/jqxgrid.grouping.js"></script>
        <script src="../jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {           
                var data = new Array();
                var firstNames =
                [
                    "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene"
                ];
                var lastNames =
                [
                    "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier"
                ];
                var productNames =
                [
                    "Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Cramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist"
                ];
                var priceValues =
                [
                    "2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0", "1.75", "3.25", "4.0"
                ];
                for (var i = 0; i < 1000; i++) {
                    var row = {};
                    var productindex = Math.floor(Math.random() * productNames.length);
                    var price = parseFloat(priceValues[productindex]);
                    var quantity = 1 + Math.round(Math.random() * 10);
                    row["firstname"] = firstNames[Math.floor(Math.random() * firstNames.length)];
                    row["lastname"] = lastNames[Math.floor(Math.random() * lastNames.length)];
                    row["productname"] = productNames[productindex];
                    row["price"] = price;
                    row["quantity"] = quantity;
                    row["total"] = price * quantity;
                    data[i] = row;
                }
                var source =
                {
                    localdata: data,
                    datatype: "array"
                };
                var dataAdapter = new $.jqx.dataAdapter(source, {
                    loadComplete: function (data) { },
                    loadError: function (xhr, status, error) { }
                });
                $("#dataTable").jqxGrid(
                 {
                     source: dataAdapter,
                     width: 670,
                     height: 450,
                     source: source,                
                     sortable: true,
                     filterable: true,
                     selectionmode: 'singlecell',
                     columns: [
                         { text: 'First Name', datafield: 'firstname', width: 100 },
                         { text: 'Last Name', datafield: 'lastname', width: 100 },
                         { text: 'Product', datafield: 'productname', width: 180 },
                         { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' },
                         { text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
                         { text: 'Total', datafield: 'total', width: 100, cellsalign: 'right', cellsformat: 'c2' }
                     ]
                 });
                $("#dataTable").on('cellselect', function (event) {
                    var columnheader = $("#dataTable").jqxGrid('getcolumn', event.args.datafield).text;
                    $("#selectedcell").html("Row: " + event.args.rowindex + ", Column: " + columnheader);
                });
            });
        </script>
    </head>
    <body>
        <div>
            <span id="selectedcell"></span>
        </div>
        <div id="dataTable"></div>
    </body>
    </html>

    Best Regards,
    Nadezhda

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


    micmor
    Participant

    Thanks! the problem was that i used Tables before and had this as source:

       var source =
                {
                    localData: tennisLista,
                    dataType: "array",
                    //dataFields:
                    //[
                    //    { name: 'veckarad', type: 'string' },
                    //    { name: 'fDate', type: 'string' },
                    //    { name: 'tDate', type: 'string' },
                    //    { name: 'pass1', type: 'string' },
                    //    { name: 'pass2', type: 'string' },
                    //    { name: 'pass3', type: 'string' },
                    //    { name: 'pass4', type: 'string' },
                    //    { name: 'pass5', type: 'string' },
                    //    { name: 'pass6', type: 'string' },
                    //    { name: 'pass7', type: 'string' },
                    //    { name: 'pass8', type: 'string' },
                    //    { name: 'pass9', type: 'string' }
                    //]
                };

    but now it works!
    Thanks again for your fast answer!
    /michel

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

You must be logged in to reply to this topic.