Visualizzazione dei risultati da 1 a 6 su 6

Discussione: disabilitare filtro

  1. #1

    disabilitare filtro

    Salve, sono nuovo nel mondo della programmazione.
    Ho un po di esperienza in php, ma in javascript ......

    ho un problema con un codice:

    ho 2 boxarea, nella prima ho un elenco di 5000 record e selezionandone alcune, vengono riportate nella seconda boxarea

    il mio problema e nel filtraggio.
    dovendo filtrare 5000 righe, il programma risulta troppo lento!!

    mi occorre che il filtraggio lo facesse solo sulle iniziali delle stringhe e non all'interno:
    esempio:

    record 1 > casa bella milano marittima
    record 2 > appartamento milano
    record 3 > milano settembre bicicletta
    record 4 > casa bici carte sapone

    se nel campo filtro inserisco milano, nel boxarea mi filtra i record 1-2-3 perche contenuto nella stringa, io voglio che mi faccia vedere solo il record 4

    come posso modificara il seguente script?
    (function($) { var settings = new Array(); var group1 = new Array(); var group2 = new Array(); var onSort = new Array(); $.configureBoxes = function(options) { var index = settings.push({ box1View: 'box1View', box1Storage: 'box1Storage', box1Filter: 'box1Filter', box1Clear: 'box1Clear', box1Counter: 'box1Counter', box2View: 'box2View', box2Storage: 'box2Storage', box2Filter: 'box2Filter', box2Clear: 'box2Clear', box2Counter: 'box2Counter', to1: 'to1', allTo1: 'allTo1', to2: 'to2', allTo2: 'allTo2', transferMode: 'move', sortBy: 'text',/**/ useFilters: true, useCounters: true, /**/useSorting: false, /*<-true*/ selectOnSubmit: true }); index--; $.extend(settings[index], options); group1.push({ view: settings[index].box1View, storage: settings[index].box1Storage, filter: settings[index].box1Filter, clear: settings[index].box1Clear, counter: settings[index].box1Counter, index: index }); group2.push({ view: settings[index].box2View, storage: settings[index].box2Storage, filter: settings[index].box2Filter, clear: settings[index].box2Clear, counter: settings[index].box2Counter, index: index }); if (settings[index].sortBy == 'text') { onSort.push(function(a, b) { var aVal = a.text.toLowerCase(); var bVal = b.text.toLowerCase(); if (aVal < bVal) { return -1; } if (aVal > bVal) { return 1; } return 0; }); } else { onSort.push(function(a, b) { var aVal = a.value.toLowerCase(); var bVal = b.value.toLowerCase(); if (aVal < bVal) { return -1; } if (aVal > bVal) { return 1; } return 0; }); } if (settings[index].useFilters) { $('#' + group1[index].filter).keyup(function() { Filter(group1[index]); }); $('#' + group2[index].filter).keyup(function() { Filter(group2[index]); }); $('#' + group1[index].clear).click(function() { ClearFilter(group1[index]); }); $('#' + group2[index].clear).click(function() { ClearFilter(group2[index]); }); } if (IsMoveMode(settings[index])) { $('#' + group2[index].view).dblclick(function() { MoveSelected(group2[index], group1[index]); }); $('#' + settings[index].to1).click(function() { MoveSelected(group2[index], group1[index]); }); $('#' + settings[index].allTo1).click(function() { MoveAll(group2[index], group1[index]); }); } else { $('#' + group2[index].view).dblclick(function() { RemoveSelected(group2[index], group1[index]); }); $('#' + settings[index].to1).click(function() { RemoveSelected(group2[index], group1[index]); }); $('#' + settings[index].allTo1).click(function() { RemoveAll(group2[index], group1[index]); }); } $('#' + group1[index].view).dblclick(function() { MoveSelected(group1[index], group2[index]); }); $('#' + settings[index].to2).click(function() { MoveSelected(group1[index], group2[index]); }); $('#' + settings[index].allTo2).click(function() { MoveAll(group1[index], group2[index]); }); if (settings[index].useCounters) { UpdateLabel(group1[index]); UpdateLabel(group2[index]); } if (settings[index].useSorting) { SortOptions(group1[index]); SortOptions(group2[index]); } $('#' + group1[index].storage + ',#' + group2[index].storage).css('display', 'none'); if (settings[index].selectOnSubmit) { $('#' + settings[index].box2View).closest('form').submit(function() { $('#' + settings[index].box2View).children('option').attr('selected', 'selected'); }); } }; function UpdateLabel(group) { var showingCount = $("#" + group.view + " option").size(); var hiddenCount = $("#" + group.storage + " option").size(); $("#" + group.counter).text('Showing ' + showingCount + ' of ' + (showingCount + hiddenCount)); } function Filter(group) { var index = group.index; var filterLower; if (settings[index].useFilters) { filterLower = $('#' + group.filter).val().toString().toLowerCase(); } else { filterLower = ''; } $('#' + group.view + ' option').filter(function(i) { var toMatch = $(this).text().toString().toLowerCase(); return toMatch.indexOf(filterLower) == -1; }).appendTo('#' + group.storage); $('#' + group.storage + ' option').filter(function(i) { var toMatch = $(this).text().toString().toLowerCase(); return toMatch.indexOf(filterLower) != -1; }).appendTo('#' + group.view); try { $('#' + group.view + ' option').removeAttr('selected'); } catch (ex) { } if (settings[index].useSorting) { SortOptions(group); } if (settings[index].useCounters) { UpdateLabel(group); } } function SortOptions(group) { var $toSortOptions = $('#' + group.view + ' option'); $toSortOptions.sort(onSort[group.index]); $('#' + group.view).empty().append($toSortOptions); } function MoveSelected(fromGroup, toGroup) { if (IsMoveMode(settings[fromGroup.index])) { $('#' + fromGroup.view + ' option:selected').appendTo('#' + toGroup.view); } else { $('#' + fromGroup.view + ' option:selected:not([class*=copiedOption])').clone().appendTo('#' + toGroup.view).end().end().addClass('copiedOption') ; } try { $('#' + fromGroup.view + ' option,#' + toGroup.view + ' option').removeAttr('selected'); } catch (ex) { } Filter(toGroup); if (settings[fromGroup.index].useCounters) { UpdateLabel(fromGroup); } } function MoveAll(fromGroup, toGroup) { if (IsMoveMode(settings[fromGroup.index])) { $('#' + fromGroup.view + ' option').appendTo('#' + toGroup.view); } else { $('#' + fromGroup.view + ' option:not([class*=copiedOption])').clone().appendTo('#' + toGroup.view).end().end().addClass('copiedOption') ; } try { $('#' + fromGroup.view + ' option,#' + toGroup.view + ' option').removeAttr('selected'); } catch (ex) { } Filter(toGroup); if (settings[fromGroup.index].useCounters) { UpdateLabel(fromGroup); } } function RemoveSelected(removeGroup, otherGroup) { $('#' + otherGroup.view + ' option.copiedOption').add('#' + otherGroup.storage + ' option.copiedOption').remove(); try { $('#' + removeGroup.view + ' option:selected').appendTo('#' + otherGroup.view).removeAttr('selected'); } catch (ex) { } $('#' + removeGroup.view + ' option').add('#' + removeGroup.storage + ' option').clone().addClass('copiedOption').appendTo ('#' + otherGroup.view); Filter(otherGroup); if (settings[removeGroup.index].useCounters) { UpdateLabel(removeGroup); } } function RemoveAll(removeGroup, otherGroup) { $('#' + otherGroup.view + ' option.copiedOption').add('#' + otherGroup.storage + ' option.copiedOption').remove(); try { $('#' + removeGroup.storage + ' option').clone().addClass('copiedOption').add('#' + removeGroup.view + ' option').appendTo('#' + otherGroup.view).removeAttr('selected'); } catch (ex) { } Filter(otherGroup); if (settings[removeGroup.index].useCounters) { UpdateLabel(removeGroup); } } function ClearFilter(group) { $('#' + group.filter).val(''); $('#' + group.storage + ' option').appendTo('#' + group.view); try { $('#' + group.view + ' option').removeAttr('selected'); } catch (ex) { } if (settings[group.index].useSorting) { SortOptions(group); } if (settings[group.index].useCounters) { UpdateLabel(group); } } function IsMoveMode(currSettings) { return currSettings.transferMode == 'move'; } })(jQuery);
    Immagini allegate Immagini allegate

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    74
    Inserisci un link ad una pagina di esempio, e quando posti codice, sia php o js, usa i tag CODE o PHP... così non si capisce...
    ..
    "Voi che avete gl'intelletti sani,mirate la dottrimna che s'asconde dietro il velame delli versi strani".

  3. #3
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    Tanto per provare, prova a cambiare questo:

    return toMatch.indexOf(filterLower) != -1;

    cosi':

    return toMatch.indexOf(filterLower) == 0;


    ... ma e' solo un tentativo, non posso provarlo se non conosco tutta la tua pagina.


    ps: occhio ai titoli per la prossima: questo non e' abbastanza chiaro
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

  4. #4
    Grazie per la collaborazione, vi sono molto grato!
    ho postato tutto su http://bunz-project.com/TEST/bio.php
    lo script in questione è js/forms/jquery.dualListBox.js

    ho provato a modificarlo, ma nn va!!

    ps: correzione nell'esempio: digitando milano deve dare solo il record 3 e non 4. porobabilmente era gia chiaro prima, meglio precisare

    grazie veramente, ci sto battendo la testa da un bel po!!

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    74
    Come suggeriva br1, modifica la funzione filter in questo modo:
    Codice PHP:
    function Filter(group) {
        var 
    index group.index;
        var 
    filterLower;
        if (
    settings[index].useFilters) {
            
    filterLower = $('#' group.filter).val().toString().toLowerCase();
        } else {
            
    filterLower '';
        }
        $(
    '#' group.view ' option').filter(function(i) {
            var 
    toMatch = $(this).text().toString().toLowerCase();
            return 
    toMatch.indexOf(filterLower) != 0;
        }).
    appendTo('#' group.storage);
        $(
    '#' group.storage ' option').filter(function(i) {
            var 
    toMatch = $(this).text().toString().toLowerCase();
            return 
    toMatch.indexOf(filterLower) == 0;
        }).
    appendTo('#' group.view);
        try {
            $(
    '#' group.view ' option').removeAttr('selected');
        } catch (
    ex) { }
        if (
    settings[index].useSorting) {
            
    SortOptions(group);
        }
        if (
    settings[index].useCounters) {
            
    UpdateLabel(group);
        }

    Le modifiche sono 2:
    Codice PHP:
    $('#' group.view ' option').filter(function(i) {
            var 
    toMatch = $(this).text().toString().toLowerCase();
            return 
    toMatch.indexOf(filterLower) != 0;
        }).
    appendTo('#' group.storage); 
    fa in modo che se la stringa non corrisponde, sia eliminata dalla lista visibile, ma memorizzata a parte
    Codice PHP:
    $('#' group.storage ' option').filter(function(i) {
            var 
    toMatch = $(this).text().toString().toLowerCase();
            return 
    toMatch.indexOf(filterLower) == 0;
        }).
    appendTo('#' group.view); 
    fa in modo che l'elemento che invece corrisponde, rimanga in lista.
    ..
    "Voi che avete gl'intelletti sani,mirate la dottrimna che s'asconde dietro il velame delli versi strani".

  6. #6
    grandi!!! funziona!!!!
    GRAZIEEEEEEE!!!!!!!!!

    per velocizzare un po la gestione posso fare altro secondo voi?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.