locked
filter a list by Max(date) RRS feed

  • Question

  • Hi all,

    Not sure if this is possible, but here goes :)

    I have a list that contains [locationNo],[Last check date]

    it is grouped by [locationNo]

    LOC1 2/1/2011

    LOC1 1/15/2011

    LOC2 8/1/2011

    LOC2 9/1/2011

    my users would like only to see the latest checked Date

    Loc1 2/1/11

    LOC2 9/1/11

    Is there a way to create a filtered view by MAX([Last Date Checked]) ?  it complains about my syntax :)

    TIA,

    Joe

    Wednesday, September 14, 2011 8:25 PM

Answers

  • I really put some time into thinking about doing this. But I was unable to achieve this using the stand ootb stuff. I did however come up with a jQuery solution that you could add to the page via content editor.

    This would work based on two variables that you would need to change. You need to tell it the View Name that appears on the site. This is so that it would only filter on that select view. And you need to tell it what colunm number to check on. See picture, then look at the provided script, the first two VARs you would change to match your list setup.

    <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.min.js'></script>
    
    <script type='text/javascript'>
    var ViewName = "RowFilter";
    var ColumnNumber = 8;
    
    function checkPage(){
    	if($(".ms-viewselector a").text() == ViewName){
    		$(".ms-listviewtable tbody[id^='tbod']").each(function(){
    		 var x = $(this).text();
    		 if(x != "Loading...." || x != ""){
    			clearInterval(pageChecker);
    			FilterItems()
    			return false;
    		 }
    		});
    	}				
    	else
    	{
    		clearInterval(pageChecker);
    	}
    }
    
    function FilterItems()
    {
    	$(".ms-listviewtable tbody[id^='tbod']").children().hide();
    
    	var maxDate = 0;
    	var showRow = "";
    	
    	$(".ms-listviewtable tbody[id^='tbod']").each(function(){
    		$(this).find("tr").each(function(i){
    			var itemDate = $(this).children().eq(ColumnNumber).text();
    			if(itemDate != ""){
    				itemDate = itemDate.replace(/\//g,'');
    				if(itemDate > maxDate){
    					maxDate = parseInt(itemDate) ;
    					showRow = i;
    				}
    			}
    		});
    		$(this).find("tr").eq(showRow).show();
    	});
    }
    
    var pageChecker = setInterval("checkPage()", 1000);
    
    
    </script>
    
    

     

    It might not be what you were looking for but it works


    -tom daly
    • Marked as answer by Jaylou Thursday, September 15, 2011 7:32 PM
    Thursday, September 15, 2011 4:38 AM

All replies

  • I really put some time into thinking about doing this. But I was unable to achieve this using the stand ootb stuff. I did however come up with a jQuery solution that you could add to the page via content editor.

    This would work based on two variables that you would need to change. You need to tell it the View Name that appears on the site. This is so that it would only filter on that select view. And you need to tell it what colunm number to check on. See picture, then look at the provided script, the first two VARs you would change to match your list setup.

    <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.min.js'></script>
    
    <script type='text/javascript'>
    var ViewName = "RowFilter";
    var ColumnNumber = 8;
    
    function checkPage(){
    	if($(".ms-viewselector a").text() == ViewName){
    		$(".ms-listviewtable tbody[id^='tbod']").each(function(){
    		 var x = $(this).text();
    		 if(x != "Loading...." || x != ""){
    			clearInterval(pageChecker);
    			FilterItems()
    			return false;
    		 }
    		});
    	}				
    	else
    	{
    		clearInterval(pageChecker);
    	}
    }
    
    function FilterItems()
    {
    	$(".ms-listviewtable tbody[id^='tbod']").children().hide();
    
    	var maxDate = 0;
    	var showRow = "";
    	
    	$(".ms-listviewtable tbody[id^='tbod']").each(function(){
    		$(this).find("tr").each(function(i){
    			var itemDate = $(this).children().eq(ColumnNumber).text();
    			if(itemDate != ""){
    				itemDate = itemDate.replace(/\//g,'');
    				if(itemDate > maxDate){
    					maxDate = parseInt(itemDate) ;
    					showRow = i;
    				}
    			}
    		});
    		$(this).find("tr").eq(showRow).show();
    	});
    }
    
    var pageChecker = setInterval("checkPage()", 1000);
    
    
    </script>
    
    

     

    It might not be what you were looking for but it works


    -tom daly
    • Marked as answer by Jaylou Thursday, September 15, 2011 7:32 PM
    Thursday, September 15, 2011 4:38 AM
  • Thank you very much,

    I am a bit confused, where would I place this code?  Would I add a Content query web part?

     

    Thanks again,

    Joe

    Thursday, September 15, 2011 12:09 PM
  • Yes just edit the page and add it that in a content editor webpart. It should work if you have a view similiar to what I have depicted.

     


    -tom daly
    Thursday, September 15, 2011 6:51 PM
  • Thanks.  I will let you know how it goes :)
    Thursday, September 15, 2011 7:11 PM