jQWidgets Forums

jQuery UI Widgets Forums Grid Disable/hide a button from column

This topic contains 4 replies, has 2 voices, and was last updated by  basim.sherif 12 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Disable/hide a button from column #6217

    basim.sherif
    Participant

    How can I disable/hide a button from column by checking a particular condition. Following is my code..

      $("#jqxgrid").jqxGrid(
             {
                 source: source,
                 theme: theme,
    			 width: 630,
    			 height:1000,
                             autoheight: true,
    			 autowidth: true,
    		         sortable: true,
    			 editable:true,
                             selectionmode: 'none',
    
             columns: [
    
    		  { text: 'Entry Date', datafield: 'date', width: 200},
    	          { text: 'Unit registration no.', datafield: 'receiptno', width: 200},
                      { text: 'Unit', datafield: 'unit', width:170,cellsalign: 'left' },
    	          { text: '       ', columntype: 'button',value:'Print', datafield: 'Print', cellsrenderer: function () {
                         return "Reprint";
    
                     }}
    
               ]
             });
    Disable/hide a button from column #6236

    Peter Stoev
    Keymaster

    Hi basim.sherif,

    It isn’t possible to disable or hide a button from a buttons columns. However, this should be possible by using a normal column with custom cellsrenderer implementation and the cellsrenderer returns a standard button. I suggest you to take a look at this sample: customcolumn.htm. The sample illustrates how to implement a cellsrenderer function which returns custom HTML which depends on the cell’s value.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Disable/hide a button from column #6259

    basim.sherif
    Participant

    Thanks for your help.I tried the sample grid about custom column.But I didnt get any idea.Can you be more detail? It will be grateful if you provide a sample code to implement cellsrenderer with buttons. Thank you…

    Disable/hide a button from column #6262

    Peter Stoev
    Keymaster

    Hi basim.sherif,

    Here’s a sample which enables/disables buttons in a column using the cellsrenderer function. When a button is clicked, a function called buttonClick is invoked.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <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.columnsresize.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="../../scripts/gettheme.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var theme = getTheme();
    // prepare the data
    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 < 200; 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);
    $("#jqxgrid").jqxGrid(
    {
    width: 670,
    source: dataAdapter,
    theme: theme,
    columnsresize: true,
    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',
    cellsrenderer: function (row, column, value) {
    if (value < 5) {
    return '<input type="button" disabled="true" value="Delete"/>';
    }
    return '<input id="button' + row +'" onClick="buttonClick(event)" type="button" value="Delete"/>';
    }
    },
    { text: 'Unit Price', dataField: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
    { text: 'Total', dataField: 'total', cellsalign: 'right', minwidth: 100, cellsformat: 'c2' }
    ]
    });
    });
    </script>
    </head>
    <body class='default'>
    <div id='jqxWidget'>
    <div id="jqxgrid">
    </div>
    <script type="text/javascript">
    function buttonClick(event) {
    alert("clicked button with id: " + event.target.id);
    }
    </script>
    </div>
    </body>
    </html>

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Disable/hide a button from column #6263

    basim.sherif
    Participant

    Peter! you are awesome! 🙂 thanks bro….Thank you very much for your support… 🙂

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

You must be logged in to reply to this topic.