jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Disable jqxGrid row edit when value in one column = 1
Tagged: conditions, disable edit, grid, parse row
This topic contains 8 replies, has 3 voices, and was last updated by Klaus H 12 years, 1 month ago.
-
Author
-
Hi all,
I’ve been researching for days and haven’t found a solution to this, before requesting official support I want to give the forum a shot, we have a commercial license btw.
I have a jqxGrid with JSON data. There are about 40 columns and thousands of records. I was recently asked to add 3 new columns to the database to record Boolean values (0 and 1). These new columns are not being displayed in the grid but are being loaded in the JSON file.
Escentially what they want is if the value on the 43rd(hidden) column is = 0 then editing is allowed for the row and if that value is = 1 then disable editing.
I know that cellbeginedit will help me in this case but I honestly don’t know how to parse the data in the row and pass it to that option.
If someone can give me a quick example I would really appreciate it.
Thanx!!
Sorry, after a word with my boss the requirements just changed. The 3 columns will be shown in the grid as checkboxes so I need to get the data from one of the visible rows as its not hidden anymore.
Thanx again!!
Hi,
The following sample: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/disableeditingofrows.htm?web shows how to disable the editing of a row under some condition.
Best regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Peter,
Thanx for the example, I saw that millions of times before but as you may probably realize if you read the entire post is that I need to be able to build a condition based on one column’s value, if the value of a specific column is 1 disable it, if the value is 0 enable it.
I hope I’m clear now.
Thanx!
Hi,
As you may see in the sample, the “cellbeginedit” function is used. That function is called each time an edit operation begins. Inside that function you may allow or not whether the cell will be edited under some custom condition.
Best regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/So there is no way to parse the data in a specific row Peter?
I don’t know if I’ve been clear enough but if you read my initial post I do know about the cellbeginedit function and all I’m looking for is an example of how to get the value from a specific column so that I can build the condition.
Hello,
if I may – inside the cellbeginedit event, you can use args.rowindex to access the rowdata with
var data = $('#jqxGrid').jqxGrid('getrowdata', args.rowindex);
and then you can check the value with data.attributename for each of the columns.
Kalus,
Thanx for the reply. I’m not sure about the syntax.
If I want to access COLUMN 15 could it be something like the line below?
$(‘#jqxGrid’).jqxGrid(‘getrowdata’, args.rowindex(’15’));
Or is it something else…?
Thanx!!
Hi,
you have to know the attribute name of the column as defined in the datasource, which looks something like this:
var source ={ localdata: data, datatype: "array", datafields: [ { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'available', type: 'bool' }, { name: 'quantity', type: 'number' }, { name: 'price', type: 'number' }, { name: 'date', type: 'date' } ], updaterow: function (rowid, rowdata, commit) { // synchronize with the server - send update command commit(true); }};
The column then may or may not be displayed in the grid itself:
$("#jqxgrid").jqxGrid({ columns: [ { text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 90, cellbeginedit: cellbeginedit, cellsrenderer: cellsrenderer }, { text: 'Last Name', datafield: 'lastname', columntype: 'textbox', width: 90, cellbeginedit: cellbeginedit, cellsrenderer: cellsrenderer }, { text: 'Product', columntype: 'dropdownlist', datafield: 'productname', width: 177, cellbeginedit: cellbeginedit, cellsrenderer: cellsrenderer }, { text: 'Available', datafield: 'available', columntype: 'checkbox', width: 67, cellbeginedit: cellbeginedit}, { text: 'Ship Date', datafield: 'date', columntype: 'datetimeinput', width: 90, cellsalign: 'right', cellsformat: 'd', cellbeginedit: cellbeginedit, validation: function (cell, value) { var year = value.getFullYear(); if (year >= 2013) { return { result: false, message: "Ship Date should be before 1/1/2013" }; } return true; }, cellsrenderer: cellsrenderer }, { text: 'Quantity', datafield: 'quantity', width: 70, cellsalign: 'right', columntype: 'numberinput', validation: function (cell, value) { if (value < 0 || value > 150) { return { result: false, message: "Quantity should be in the 0-150 interval" }; } return true; }, initeditor: function (row, cellvalue, editor) { editor.jqxNumberInput({ decimalDigits: 0, digits: 3 }); }, cellbeginedit: cellbeginedit, cellsrenderer: cellsrenderer }, { text: 'Price', datafield: 'price', width: 65, cellsalign: 'right', cellsformat: 'c2', columntype: 'numberinput', validation: function (cell, value) { if (value < 0 || value > 15) { return { result: false, message: "Price should be in the 0-15 interval" }; } return true; }, initeditor: function (row, cellvalue, editor) { editor.jqxNumberInput({ digits: 3 }); }, cellbeginedit: cellbeginedit, cellsrenderer: cellsrenderer } ]});
That does not really matter. What you get back from getrowdata is a data object that is used to represent the row. So let’s assume I want to check available – First, here’s the example from the website:
var cellbeginedit = function (row, datafield, columntype, value) { if (row == 0 || row == 2 || row == 5) return false;}
Change this to:
var cellbeginedit = function (row, datafield, columntype, value) { var data = $('#jqxGrid').jqxGrid('getrowdata', row); if(data.available == false) return false;}
Use the three columns that you need to evaluate and then it should work, if you use the cellbeginedit: cellbeginedit attribute in the grid columns definition for every editable field.
-
AuthorPosts
You must be logged in to reply to this topic.