Reputation: 299
I am trying to obtain a cell's text value from a flexigrid. However I keep getting that error.
This is my function for retrieving a specific cell's text(Flexigrid doesnt have "attr" it has "abbr" instead).
function getSelectedCopyDates() {
var arr = new Array();
debugger;
//for every row that has a checked checkbox
$("tr").has(".noteCheckBox:checked").each(function(i) {
if ($(this.id) !== "checkAllNotes") {
//push the value of column(FName, LName) into the array
arr.push($("#" + this.id + "> td[abbr='EventDate'] > div").text());
}
});
return arr;
}
I only get that error when I click on "checkAllNotes"(main check box ). If I check a checkbox manually then everything works fine.
Here is my flexigrid layout:
$('#viewNotesGrid').flexigrid({
url: url,
dataType: 'json',
method: 'get',
colModel: [{
display: '<input type="checkbox" class="noteCheckBox" id="checkAllNotes" />',
name: 'checkBox',
width: 20,
sortable: false,
align: 'center',
process: showDescription
}, {
display: 'Date',
name: 'EventDate',
width: 80,
sortable: true,
align: 'center',
process: showDescription
},
Upvotes: 3
Views: 18717
Reputation: 26687
1st problem is that $("tr").has(".noteCheckBox:checked")
returns tr elements, not input checkboxes.
2nd problem: $(this.id) !== "value"
will never work. You are creating jQuery object and comparing it with string. Should be this.id !== "value"
3rd problem: already explained in previous answer. If element doesn't seem to have id, then "#" + this.id + ">
would result in "#>"
, and you actually want to compare id of special input field, not tr.
Making few assumptions here, but this might work:
function getSelectedCopyDates() {
var arr = new Array();
//for every row that has a checked checkbox
$("tr .noteCheckBox:checked").each(function (i) {
if (this.id !== "checkAllNotes") {
var tr = $(this).parents("tr")[0]; // going back to parent tr
arr.push($(tr).find(" > td[abbr='EventDate'] > div").text());
}
});
return arr;
}
Upvotes: 2
Reputation: 191789
I think you mean to use this.id ==
vs. $(this.id) ==
. It also seems like the error may be because this.id
is empty (jQuery will throw that error on $("#>")
, but the error message also seems to include the >
, so I'm not sure).
Upvotes: 2