2013-07-18 8 views
12

Fiddleखींच

$(document).live('mouseup', function() { 
    flag = false; 
}); 

var colIndex; 
var lastRow; 

$(document).on('mousedown', '.csstablelisttd', function (e) { 
    //This line gets the index of the first clicked row. 
    lastRow = $(this).closest("tr")[0].rowIndex; 

    var rowIndex = $(this).closest("tr").index(); 
    colIndex = $(e.target).closest('td').index(); 
    $(".csstdhighlight").removeClass("csstdhighlight"); 
    if (colIndex == 0 || colIndex == 1) //)0 FOR FULL TIME CELL AND 1 FOR TIME SLOT CELL. 
    return; 
    if ($('#contentPlaceHolderMain_tableAppointment tr').eq(rowIndex).find('td').eq(colIndex).hasClass('csstdred') == false) { 
     $('#contentPlaceHolderMain_tableAppointment tr').eq(rowIndex).find('td').eq(colIndex).addClass('csstdhighlight'); 

     flag = true; 
     return false; 
    } 
}); 

मैं तालिका सेल पर खींच रहा हूँ। खींचते समय (नीचे की दिशा में आगे बढ़ें) मुझे टेबल स्क्रॉल भी ले जाना है। और मैं कोशिकाओं के विपरीत (ऊपर की दिशा) का चयन करना चाहता हूं। मुझे क्या करना चाहिए।

मैंने टीआर कक्षा में चयन किया है।

+0

से क्या समझते हैं, आप ** उन पर माउस खींचकर, बजाय की पंक्तियों को ऊपर या नीचे खींचकर पंक्तियों ** चयन करना चाहते हैं। क्या वह सही है ? –

+0

कृपया इसे देखें, आपको jquery [तालिका ड्रैग और ड्रॉप के लिए JQury प्लगइन] का उपयोग करके तालिका कक्षों को खींचने के लिए कुछ विचार मिलेगा (http://isocra.com/2008/02/table-drag-and-drop-jquery-plugin/) [टेबल पर दूसरी पंक्ति से तालिका पंक्ति खींचें और छोड़ें] (http://stackoverflow.com/questions/14907809/drag-and-drop-table-row-from-one-tabs-) अग्रिम धन्यवाद –

उत्तर

5

अपडेट किया गया jsFiddle: http://jsfiddle.net/qvxBb/2/

इस तरह अक्षम सामान्य चयन:

.myselect { 
    -webkit-touch-callout: none; 
    -webkit-user-select: none; 
    -khtml-user-select: none; 
    -moz-user-select: moz-none; 
    -ms-user-select: none; 
    user-select: none; 
} 

और इस तरह जावास्क्रिप्ट के साथ पंक्ति चयन संभाल:

// wether or not we are selecting 
var selecting = false; 
// the element we want to make selectable 
var selectable = '.myselect tr:not(:nth-child(1)) td:nth-child(3)'; 

$(selectable).mousedown(function() { 
    selecting = true; 
}).mouseenter(function() { 
    if (selecting) { 
     $(this).addClass('csstdhighlight'); 
     fillGaps(); 
    } 
}); 
$(window).mouseup(function() { 
    selecting = false; 
}).click(function() { 
    $(selectable).removeClass('csstdhighlight'); 
}); 

// If you select too fast, js doesn't fire mousenter on all cells. 
// So we fill the missing ones by hand 
function fillGaps() { 
    min = $('td.csstdhighlight:first').parent().index(); 
    max = $('td.csstdhighlight:last').parent().index(); 
    $('.myselect tr:lt('+max+'):gt('+min+') td:nth-child(3)').addClass('csstdhighlight'); 
} 

मैं बस एचटीएमएल में एक कक्षा जोड़ा। मैंने जो कुछ भी दिखाया है उसके अलावा अपरिवर्तित में सभी HTML और CSS।

अपडेट किया गया jsFiddle: http://jsfiddle.net/qvxBb/2/

+0

हाय Pinouchon ru वहाँ – John

+0

@Mans बस आपको सवाल पूछते हैं ... यह त्वरित संदेश नहीं है। –

3

आपकी तालिका के साथ कई समस्याएं हैं, लेकिन मैं आपके द्वारा पूछे गए एक को सही कर दूंगा।
अपनी मेज स्क्रॉल करने के लिए जब अपने माउस कंटेनर के बाहर मिलता है, अपने mousedown ईवेंट हैंडलर के अंदर इस कोड जोड़ें:

$('body').on('mousemove', function(e){ 
    div = $('#divScroll');  
    if(e.pageY > div.height() && (e.pageY - div.height()) > div.scrollTop()) { 
     div.scrollTop(e.pageY - div.height()); 
    } 
}); 

और इस, अपने mouseup ईवेंट हैंडलर के अंदर:

$('body').off('mousemove'); 

देखें updated Fiddle

लेकिन अब, एक और मुद्दा दिखाई देता है। यह आपके शेष कोड की वजह से है। रेखाएं चयनित नहीं हैं क्योंकि माउस कॉलम छोड़ देता है।

+0

आपके लिए धन्यवाद जवाब .... सेल चयन छात्र नाम coloumn पर ऊपर और नीचे की दिशा हो .. मुझे – John

3

return false;

अंदर
$('#contentPlaceHolderMain_tableAppointment tr').eq(rowIndex).find('td').eq(colIndex).addClass('csstdhighlight'); 
    flag = true; 
    return false; //Remove this line 
} 

क्योंकि return false; बंद हो जाता है ब्राउज़र डिफ़ॉल्ट व्यवहार (स्वचालित रूप से स्क्रॉल) निकालने का प्रयास करें।

DEMO

+0

खान कैसे करना चाहिए मुझे छात्र नाम coloumn पर ऊपर और नीचे दिशा जाना है ... पहले और दूसरे कॉलम नहीं ... \ – John

संबंधित मुद्दे