OlegKi / jqGrid-plugins

some plugins or extensions to jqGrid
36 stars 15 forks source link

Cannot read property 'dynamicLink' of undefined in 4.8.0 #5

Closed kobruleht closed 9 years ago

kobruleht commented 9 years ago

Trying to use dynamiclink formatter in free jqgrid 4.8.0 from git master causes error

Uncaught TypeError: Cannot read property 'dynamicLink' of undefined

at line

$.extend($.fn.fmatter.dynamicLink, {

OlegKi commented 9 years ago

It sounds very strange. Could you include the demo which reproduces the problem?

By the way I don't included jQuery.jqGrid.dynamicLink.js in the plugin directory of free jqGrid 4.8, because I extended the possibilities of formatter: "showlink" in free jqGrid 4.8. See the wiki article for more details.

kobruleht commented 9 years ago

For unknown reason $.fn is empty in 4.8: untitled

In 4.6 it is filled. Same exception occurs in clickable checkbox formatter also. Code from http://www.trirand.com/blog/?page_id=393/feature-request/make-disabled-checkbox-of-the-checkbox-formatter-clickable/ http://stackoverflow.com/questions/13920810/how-to-fix-javascript-exception-if-oleg-clickablecheckboxformatter-is-used-in-jq

    $.extend($.fn.fmatter, {
        clickableCheckbox: function (cellValue, options) {
            var op = $.extend({}, $.jgrid.formatter.checkbox, options.colModel.formatoptions),
                ds = op.disabled === true ? 'disabled="disabled"' : '';
            if ($.fmatter.isEmpty(cellValue) || cellValue === undefined) { // $.fmatter.isUndefined(cellValue)) {
                cellValue = $.fn.fmatter.defaultFormat(cellValue, op);
            }
            cellValue = String(cellValue).toLowerCase();
            return '<div style="position:relative"><input type="checkbox"' +
                (cellValue.search(/(false|0|no|off)/i) < 0 ? " checked='checked' " : "") +
                ' value="' + cellValue + '" offval="no" ' + ds +
                '/><div title="' + (options.colName || options.colModel.label || options.colModel.name) +
                '" style="position:absolute;top:0px;left:0px;right:100%;bottom:100%;background:white;' +
                'width:100%;height:100%;zoom:1;filter:alpha(opacity=0);opacity:0;"></div></div>';
        }
    });

    $.extend($.fn.fmatter.clickableCheckbox, {
        unformat: function (cellValue, options, elem) {
            var cbv = (options.colModel.editoptions) ?
                    options.colModel.editoptions.value.split(":") :
                    ["Yes", "No"];
            return $('input', elem).is(":checked") ? cbv[0] : cbv[1];
        }
    });

Can this also added or how to fill $.fn ?

OlegKi commented 9 years ago

$ and $.fn will be filled by jQuery. Directly after including jQuery (with the line like <script src="jquery-1.11.2.min.js"></script>) the $.fn will be initialized and have all public methods like $.fn.attr, $.fn.after and so on. So if $.fn is undefined then you not yet included jQuery. The object $.fn.fmatter will be defied by jqGrid at the beginning of jquery.fmatter.js. So the only rule is: you should include clickableCheckbox or dynamicLink formatters after jquery.jqGrid.min.js (or jquery.jqGrid.src.js).

By the way I would recommend you to use Font Awesome and formatter: "checkboxFontAwesome4" or template: "booleanCheckboxFa". See here for details. The formatter: "checkboxFontAwesome4" works more quickly as formatter: "clickableCheckbox" or formatter: "checkbox" in all web browsers which I tested.

If you do still have some problems you should post the demo which reproduces the problem.

kobruleht commented 9 years ago

It was my mistake