17- انتخاب فقط یک ردیف از گرید
منتشر شده توسط سیدحمیدرضا میرحسینی, ویرایش شده توسط: در تاریخ 1398/11/5 شنبه 14:29
|
|
var gridId = "productsList"; //set to the ID of the grid var checkboxId = "shipAbroad"; //set to the ID of the checkbox field inside the grid var checkboxColNo = 0; //set to the column number of the checkbox (start counting from zero); var reGridField = new RegExp("^\\["+gridId+"\\]\\[(\\d+)\\]\\["+checkboxId+"\\]$"); var formId = $("form").prop("id"); $("#"+formId).setOnchange( function(fieldId, newVal, oldVal) { var aMatch = fieldId.match(reGridField); //if the checkbox was marked in the grid, then unmark the checkbox in all other rows in the grid: if (aMatch && newVal == '"1"') { var selectedRowNo = aMatch[1] - 1; //subtract 1 because start counting grid rows from zero var aGridVals = $("#"+gridId).getValue(); //loop through the grid looked for other marked rows: for (var i = 0; i < aGridVals.length; i++) { //if the checkbox in the row is marked and not the currently selected row, then unmark it: if (aGridVals[i][checkboxColNo] == '1' && i != selectedRowNo) { //add 1 to row and column numbers because setValue() starts counting from 1, not 0: var aGridVals = $("#"+gridId).setValue('0', i+1, checkboxColNo+1); } } } }) //when the form is submitted, make sure that one checkbox in the grid is marked: $("#"+formId).setOnSubmit( function() { var aGridVals = $("#"+gridId).getValue(); var markedRowNo = null; //loop through the grid to check that there is one marked checkbox in the grid: for (var i = 0; i < aGridVals.length; i++) { if (aGridVals[i][checkboxColNo] == '1') { if (markedRowNo) { alert("Both rows "+markedRowNo+" and "+(i+1)+" cannot be marked. Please only select one."); return false; //stop the submit action } markedRowNo = i+1; } if (markedRowNo === null) { alert("One row in the grid must be marked in the row."); return false; } } })
|
|
|