jQuery UI Widgets › Forums › Grid › Set Grid Button Static ID
Tagged: Button, buttonclick, columntype, grid, id, jqxgrid
This topic contains 5 replies, has 3 voices, and was last updated by Dimitar 9 years, 3 months ago.
-
Author
-
Hello, I have column which columntype is button. I need to do some events related to that button and therefore I need to assign a static id to that button. How can I set the ID of that button ? Thank you
Hello C.S.Putera,
You cannot add ids to the buttons in the
columntype: 'button'
but you can call your methods in the buttonclick callback, as shown in the demo Popup Editing.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Okay. Thank you Dimitar for the answer.
But can I retrieve the generated ID ? On buttonclick I call :alert($(this).attr("id"));
But it shows empty string. If I cannot set the ID before hand, perhaps I could set the ID after it is generated ?
Hi C.S.Putera,
Here is a suggestion:
$("#jqxgrid").jqxGrid( { width: 850, source: dataAdapter, pageable: true, autoheight: true, ready: function () { var buttons = $("#contenttablejqxgrid .jqx-button"); $(buttons[0]).attr("id", "customId"); },
Note that the id contenttablejqxgrid depends on the id of your grid. If it is myGrid, the content table’s id will be contenttablemyGrid.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
I need help here. thanks for the comment above. The above part will only help to select one single rows button. But i want to select the entire columns button. so i modified the code as per my needs. Here it is
—————CSS———
.customId{
background-color:red;
}.customId1{
background-color:blue;
}—————Javascript———
ready: function () {
var buttons = $(“#contenttablejqxgrid .jqx-button”);
for (i=0; i<buttons.length;i++) {
if (i %2 ==0) {
$(buttons[i]).attr(“class”, “customId”);
}
else {
$(buttons[i]).attr(“class”, “customId1”);
}
}},
I have two columns and each has buttons inside them.
So this will give a red color for all buttons in one column. This will set blue as a background color to all its buttons which are inside this column.this works fine at the start because we mentioned this setting at the ready:
Once i click on some link or work on the grid, the background color vanishes. how can i make it show background color at all times and not only at the start ???
Hi purnima,
Unfortunately, this behaviour cannot be avoided. Here is another suggestion:
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <style type="text/css"> .blue { background-color: Blue; } .red { background-color: Red; } </style> <script type="text/javascript" src="../../scripts/jquery-1.11.1.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"> $(document).ready(function () { // 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 < 100; 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) { } }); $("#jqxgrid").jqxGrid( { width: 700, source: dataAdapter, 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: 100, cellsalign: 'right' }, { text: 'Button column 1', datafield: 'bC1', width: 100, columntype: 'button', cellsrenderer: function () { return 'Left button' }, cellclassname: 'blue' }, { text: 'Button column 2', datafield: 'bC2', width: 100, columntype: 'button', cellsrenderer: function () { return 'Right button' }, cellclassname: 'red' } ] }); }); </script> </head> <body class='default'> <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;"> <div id="jqxgrid"> </div> </div> </body> </html>
Alternatively, you can create the buttons with cellsrenderer and not with
columntype: 'button'
and style them as you wish there.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.