Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Disable editing on a cell. Only using javascript #18

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

icytin
Copy link

@icytin icytin commented Mar 4, 2015

For example disabling edit of column two and three:
$('#table').editableTableWidget({ editor: $(''), preventColumns: [ 2, 3 ] });

@ddykhoff
Copy link

Thanks for this, helped me with my project!

I made a couple changes on top of this:

remove the line
.css('cursor', 'pointer')

and add the following code immediately after the block that contained the removed line (so after the .keydown( ... );):

element.find('td').each(function(){
    if ($.inArray($(this).index() + 1, activeOptions.preventColumns) == -1) {
        $(this).css('cursor', 'pointer');
    }
});

This change makes it so the cursor doesn't show as a pointer (the pointing hand) on disabled cells.

@lupor0x
Copy link

lupor0x commented Mar 10, 2016

thanks worked like a charm! :)

@nicholasrpb
Copy link

hi looks like this version is not yet merged back to the master? could help to update? i want to use this feature as well. Thanks!

@nicholasrpb
Copy link

nicholasrpb commented Sep 8, 2016

Hi @ddykhoff

could send me your latest script? Now is not really clear whether is it being locked or not, because you can double click the cells but could not change the value. Really appreciate your help! Thanks!

@DRSDavidSoft
Copy link

I use the following syntax, please also add this to your next PR:

<tr>
	<td readonly> 123 </td>
</tr>

jQuery callback that I wrote:

$('td[readonly]').click(function(e) {
	e.preventDefault();
	e.stopPropagation();
});

@alexfulsome
Copy link

I like @DRDDavidSoft's solution but its worth noting that this will still allow editing on double-click, all other things being equal.

@DRSDavidSoft
Copy link

@alexfulsome This could be a potential fix for double-clicks:

$('td[readonly]').dblclick(function(e) {
	e.preventDefault();
	e.stopPropagation();
});

... or combining them:

$('td[readonly]').on('click dblclick', function(e) {
	e.preventDefault();
	e.stopPropagation();
});

@WilliSchmidt
Copy link

WilliSchmidt commented Apr 10, 2019

you still can press the control key to change the value

$('td[readonly]').on('click dblclick keydown', function (e) { e.preventDefault(); e.stopPropagation(); });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants