jQWidgets Forums
jQuery UI Widgets › Forums › Grid › how would I differentiate between a row that has data and one that doesn't?
Tagged: jquery jqxgrid
This topic contains 1 reply, has 1 voice, and was last updated by jschultz0614 9 years, 11 months ago.
-
Author
-
June 29, 2015 at 9:39 pm how would I differentiate between a row that has data and one that doesn't? #73165
I have a grid that contains n number of rows. This grid contains a column that is a checkbox and this checkbox allows the end user to either add the row or not to the database. My issue is my code is adding everything. Viable data and empty rows. How can I tell if the row is literally of 0 length?
Code for the Grid
var data = {}; var source = { localdata: data, datatype: "array", datafields: [{ name: 'UOMRelatedUnit_ID', type: 'string' }, { name: 'UOMRelatedUnit_AddItem', type: 'bool' }, { name: 'UOMRelatedUnit_Name', type: 'string' }, { name: 'UOMRelatedUnit_Abbreviation', type: 'string' }, { name: 'UOMRelatedUnit_ConversionOfBaseUnits', type: 'number' }], addrow: function(rowid, rowdata, position, commit) { //Server Action commit(T); }, updaterow: function(rowid, newdata, commit) { //Server Action commit(T); } }; var dataAdapter = new $.jqx.dataAdapter(source); $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid({ width: 500, height: 200, source: dataAdapter, editable: T, selectionmode: 'singlecell', theme: 'energyblue', showtoolbar: T, rendertoolbar: function(toolbar) { var me = this; var container = $("<div style='margin: 5px;'></div>"); toolbar.append(container); container.append('<input id="addUoMRelatedUnitsRowButton" type="button" value="Add New Row" />'); container.append('<input style="margin-left: 5px;" id="addUoMRelatedUnitsMultipleRowsButton" type="button" value="Add Multiple New Rows" />'); $("#addUoMRelatedUnitsRowButton").jqxButton(); $("#addUoMRelatedUnitsMultipleRowsButton").jqxButton(); // create new row. $("#addUoMRelatedUnitsRowButton").on('click', function() { $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('beginupdate'); var GridObject = [''] var commit = $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('addrow', null, GridObject); $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('endupdate'); }); // create new rows. $("#addUoMRelatedUnitsMultipleRowsButton").on('click', function() { $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('beginupdate'); for (var i = 0; i < 5; i++) { var GridObject = [''] var commit = $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('addrow', null, GridObject); } $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('endupdate'); }); }, columns: [{ text: '', editable: F, datafield: 'UOMRelatedUnit_ID', width: 0 }, { text: 'Add', editable: T, datafield: 'UOMRelatedUnit_AddItem', columntype: 'checkbox', width: 40 }, { text: 'Name', editable: T, datafield: 'UOMRelatedUnit_Name', columntype: 'textbox', width: 200 }, { text: 'Abbreviation', editable: T, datafield: 'UOMRelatedUnit_Abbreviation', columntype: 'textbox', width: 100 }, { text: '# of Base Unit', editable: T, datafield: 'UOMRelatedUnit_ConversionOfBaseUnits', columntype: 'textbox', width: 100 }] }); // select or unselect rows when the checkbox is checked or unchecked. $("#jqxUOMRelatedUnitsDropdownGrid").bind('cellendedit', function(event) { if (event.args.value) { $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('selectrow', event.args.rowindex); } else { $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('unselectrow', event.args.rowindex); } }); $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('beginupdate'); var GridObject = [''] var commit = $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('addrow', null, GridObject); $("#jqxUOMRelatedUnitsDropdownGrid").jqxGrid('endupdate');
Current Code for determining an empty row
if(!row.UOMRelatedUnit_AddItem || row.length === 0) { _row["Name"] = $("#txtUnitOfMeasureSetName").val(); _row["Active"] = T; _row["UnitOfMeasureTypeID"] = $("input[type='radio'][id='rblUnitOfMeasureType']:checked").val(); _row["BaseUnitID"] = $("input[type='radio'][id='rblUnitOfMeasureBaseUnit']:checked").val(); _row["RelatedUnitDisplayOrder"] = RecordCount; _row["RelatedUnitName"] = row.UOMRelatedUnit_Name; _row["RelatedUnitAbbreviation"] = row.UOMRelatedUnit_Abbreviation; _row["RelatedUnitConversionRatio"] = row.UOMRelatedUnit_ConversionOfBaseUnits; _row["UnitOfMeasureSetID"] = UnitOfMeasureSetID; _UnitOfMeasureRelatedUnitData[index++] = _row; RecordCount += 1; }
June 29, 2015 at 10:51 pm how would I differentiate between a row that has data and one that doesn't? #73166found the answer, all I need to do is check to see if the AddItem column is undefined and that did the trick:
if($.type(row.UOMRelatedUnit_AddItem) !== "undefined")
-
AuthorPosts
You must be logged in to reply to this topic.