3

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
    },
Erwin
  • 4,757
  • 3
  • 31
  • 41
user1084319
  • 299
  • 3
  • 9
  • 27

2 Answers2

2

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).

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • how could it throw an exception on an empty string if I am iterating through the selected rows. I mean the function I have without the if statement works perfectly fine except for when I tick the "id=checkAllNotes" checkbox. – user1084319 Oct 09 '12 at 19:39
  • @user1084319 don't know; I guess one of the rows is missing an id? – Explosion Pills Oct 09 '12 at 19:44
  • ah but the thing is the rows don't have id's. only the checkbox called "checkAllNotes" has an id. All the other checkboxes just have attirbute ids (abbr not attr since its a flexigrid). the "checkAllNotes" has a class thought that is the same with all the other checkboxes. – user1084319 Oct 09 '12 at 19:47
2

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;
}
Nenad
  • 24,809
  • 11
  • 75
  • 93