Once I get the e.masterRow in the detailExpand event, how do I get the field values from teh masterRow in Kendo UI Grid?
Thanks!
You should use the dataItem method which will return the data item to which the row is bound to:
var masterDataItem = masterGrid.dataItem(e.masterRow);
console.log(masterDataItem.field1);
Related
I have a grid which is editable (editable: "incell"). One of it's fields is editable with kendoDropDownList. When I edit it's value grid reacts to changes and row gets updated. However if value is empty string then it doesn't.
kendoDropDownList itself does react to changes. I added 'change' callback to it and it kicks in.
How can I manually force grid to update row from within kendoDropDownList's 'change' callback?
You can go from dropdown to parent tr to get rownumber.
After that you can do something like:
var value = drop down value
var i = Get row index....
var data = $("#grid").data("kendoGrid").dataSource.data();
data[i].YourField= value;
$("#grid").data("kendoGrid").refresh();
I am using a JQGrid, and have designed the grid such that the first column is a checkbox. I am using the property of multiselect:true, and I am not writing any code other than this to get the checkboxes. How do I fetch the values from the rows where the checkboxes are checked?
To get the selected rows, use:
var selected = $("#tableid").jqGrid('getGridParam', 'selarrrow');
selected will be set to an array of IDs of the selected rows.
To get column values from the rows, use the getCell method. See How to get the selected row id in javascript?
I am using a WebGrid to display a list of items,
I like to set the background color of the rows based on a condition. I want to set the background color of the entire row, not just one cell.
Any example?
thank you
This is an old question, but I just stumbled upon it and have an answer that I don't think is too hacky. The previous answer supplied only works if the value you're using to conditionally change the background color is the value of a table cell.
If that's not the case, you can set a data- attribute for the first cell in your table rows using the Format property of a WebGridColumn. Here, the first column of my table contains hyperlinked IDs. I'm defining it in my code-behind (controller action in MVC) and I've added a data-in-error attribute from the IsInError property of my object. You can set the value of this attribute in whatever way makes sense for your application.
new WebGridColumn
{
ColumnName = "Id",
Header = "ID",
Format = (x) => new HtmlString(String.Format("{1}", x.Value.IsInError, x.Value.Id))
});
Then, using jQuery, I find all of the rows in my table that have an anchor in the first cell of the row, and set the class of that row to 'error'.
$(document).ready(function () {
$('table tbody tr td:first-child a[data-in-error="True"]').each(function () {
$(this).parent().parent().addClass('error');
});
});
Hope this helps.
Is jQuery an option? If so, check out: http://devpinoy.org/blogs/keithrull/archive/2010/06/09/how-to-change-table-cell-color-depending-on-its-value-using-jquery.aspx
How do I pass a selected value from GridView to a DropDownList default value. The DDL always show the first item from the table. I want to be able to display the first item as the value from another GridView (selected Item).
Thank you in advance for your help.
On your DataGridview Event where you get the selected value add.
//YOur Bindinding on Dropdown
drpdown.DataSource = //;
drpdown.DataTextField = "YourTablecolumn";
drpdown.DataBind();
string gvalue = //gridselected value;
drpdown.Items.Insert(0, new ListItem(""+ gvalue +"", "0"));
drpdown.SelectedIndex = 0;
Hope this help.
Regards
how to get a value of a (hidden) column, from the selected row. that is, the cell value needs to be from the cell identied by colName, and the selected row (not using multi select). From the API i see the method getGridParam("selrow") for reading the row, may be able to combine with other methods.. but, any convenient method available? a code snippet would save lot of time... \
thanks.
You should use getCell function to read the value from the cell identified by row id. So if you need a data from the column 'MyColName' of selected row you can do this with the following code:
var grid = jQuery('#list');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'MyColName');
If you need read full data of a row you can use getRowData instead of getCell. More about methods supported by jqGrid you can read in the documentation (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods).